Skip to content

Instantly share code, notes, and snippets.

View jitsceait's full-sized avatar

Sangar Jitendra jitsceait

View GitHub Profile
@jitsceait
jitsceait / trie_insert.c
Created May 4, 2014 05:56
Trie insertion
void insert(trie *t, char key[]){
int len = strlen(key);
int i;
if(t->root == NULL){
printf("\n Trie is not initialized\n");
}
Node * current = t->root;
@jitsceait
jitsceait / trie_search.c
Last active August 29, 2015 14:00
Trie search
int search(trie *t, char key[]){
int len = strlen(key);
int i;
if(t->root == NULL){
printf("\n Trie is not initialized\n");
}
Node * current = t->root;
for(i=0; i<len; i++){
int index = GET_CHAR_INDEX(key[i]);
@jitsceait
jitsceait / reverse_words.c
Last active August 29, 2015 14:00
Program to reverse words in string
#include <stdio.h>
#include <stdlib.h>
/* This function reverses the whole string */
void reverse(char s[]){
int i=0, j;
int end = strlen(s);
for(i=0, j=end-1; i<j; i++, j--){
char temp = s[i];
@jitsceait
jitsceait / rotate_array.c
Created May 4, 2014 06:51
Program to rotate an array at a pivot
void reverse_array(int a[], int start, int end){
while(start < end){
int temp = a[start];
a[start] = a[end];
a[end] = temp;
start++;
end--;
}
@jitsceait
jitsceait / inorder_sucessor.c
Last active August 29, 2015 14:00
Program to find inorder successor in a binary search tree
#include<stdio.h>
#include<stdlib.h>
struct node{
int value;
struct node *left;
struct node *right;
};
typedef struct node Node;
@jitsceait
jitsceait / predecessor.c
Last active August 29, 2015 14:00
Program to get inorder predecessor
#include<stdio.h>
#include<stdlib.h>
struct node{
int value;
struct node *left;
struct node *right;
};
typedef struct node Node;
#include<stdlib.h>
#include<stdio.h>
typedef struct node{
int data;
struct node *next;
} Node;
Node * merge_sort(Node *a, Node *b){
Node *result = NULL;
@jitsceait
jitsceait / matrix_multi.c
Last active October 30, 2015 04:13
Program to find optimum way to multiply matrices.
#include<stdlib.h>
#include<stdio.h>
int matrix multiplication(int p[], int N){
int L,i, j, temp;
int M[N+1][N+1];
for(i=0;i<=N; i++){
@jitsceait
jitsceait / subsetsum_rec.c
Created May 4, 2014 09:46
Program to find if there is subset with given sum in given array.
#include<stdlb.h>
#include<stdio.h>
#define true 1
#define false 0
int isSubsetSum(int arr[], int n, int sum, int subset[], int count){
int i;
if(sum == 0) {
printf("\n");
@jitsceait
jitsceait / subsetsum_dyn.c
Created May 4, 2014 09:51
Program to find out if there is subset with given sum in array using dynamic programming
#include<stdlb.h>
#include<stdio.h>
int isSubsetSum1(int arr[], int n, int sum)
{
/* The value of subset[i][j] will be true if there is a
subset of set[0..j-1] */
int subset[sum+1][n+1];
int i,j;