Skip to content

Instantly share code, notes, and snippets.

@murikadan
murikadan / sort_strings.c
Created August 26, 2012 09:06
Sorting a namelist implemented as an array of pointers
void sort(char **w,int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<count-i-1;j++)
if(strcmp(w[j],w[j+1])>0)
{
char *temp=w[j];
w[j]=w[j+1];
w[j+1]=temp;
@murikadan
murikadan / linked_list_queue.c
Created August 26, 2012 11:11
Linked List implementation of quque
#include <stdio.h>
#include <stdlib.h>
struct node
{
int val;
struct node* next;
};
void enqueue(struct node**,struct node **,int);
@murikadan
murikadan / substring_generator.c
Created August 26, 2012 11:15
Function generating unique substrings of an input string
void stringgen(char *c)
{
int i=0,j=0,l;
l=strlen(c);
while(l>=1)
{
for(i=0;i<l;++i)
{
char *buf=malloc(sizeof(char)*(i+2));
for(j=0;j<=i;j++)
@murikadan
murikadan / linked_list_reverse.c
Created August 26, 2012 12:43
Program to reverse a linked list using stack
#include <stdio.h>
#include <stdlib.h>
struct node
{
int val;
struct node* next;
};
void enqueue(struct node**,struct node **,int);
@murikadan
murikadan / file_write.c
Created August 27, 2012 13:35
Write a string or a number to a file
void writestring(char *);
void writedigit(int);
void writestring(char *s)
{
FILE *fp;
char nl[]="\n";
fp=fopen("output","a");
fprintf(fp,"%s",nl);
fprintf(fp,"%s",s);
fclose(fp);
@murikadan
murikadan / input
Created August 28, 2012 05:41
To reverse K nodes in a linked list
4
1
2
3
4
5
6
7
8
9
@murikadan
murikadan / bst.c
Created August 28, 2012 10:46
Binary Search Tree
#include <stdio.h>
#include <stdlib.h>
struct bst
{
struct bst *left,*right;
int val;
};
struct bst* makenode(int);
@murikadan
murikadan / input00
Created August 29, 2012 06:00
Quick Sort Of An Integer Array
10
5
7
3
0
9
8
2
1
6
@murikadan
murikadan / hash.c
Created August 30, 2012 06:35
Linked List Sort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char *val;
struct node *next;
};
@murikadan
murikadan / binsearch.c
Created August 31, 2012 13:11
Iterative Binary Search
int binsearch(int *,int,int,int);
int binsearch(int *a,int low,int high,int key)
{
while(high>=low)
{
int mid=(low+high)/2;
if(a[mid]==key)
return 1;
else if(a[mid]>key)
high=mid-1;