Last active
October 6, 2016 09:46
-
-
Save mrprofessor/ce0e5039f40baa00bca77a53b5892ac7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Work easy...!!...Play hard*/ | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
struct nodeh | |
{ | |
int data; | |
struct nodeh *next; | |
}; | |
struct nodev | |
{ | |
int index; | |
struct nodeh *head; | |
struct nodev *link; | |
}; | |
void inserth(struct nodeh **hd,int num) | |
{ | |
struct nodeh *new,*temp; | |
new = (struct nodeh *)malloc(sizeof(struct nodeh)); | |
new->data = num; | |
new->next = NULL; | |
if(*hd == NULL) | |
{ | |
*hd = new; | |
} | |
else | |
{ | |
temp =*hd; | |
while(temp->next != NULL) | |
{ | |
temp = temp->next; | |
} | |
temp->next = new; | |
} | |
} | |
void insertv(struct nodev **hd,int num) | |
{ | |
struct nodev *new,*temp; | |
new = (struct nodev *)malloc(sizeof(struct nodev)); | |
new->index = num; | |
new->link = NULL; | |
new->head = NULL; | |
if(*hd == NULL) | |
{ | |
*hd = new; | |
} | |
else | |
{ | |
temp = *hd; | |
while(temp->link != NULL) | |
{ | |
temp = temp->link; | |
} | |
temp->link = new; | |
} | |
} | |
int getmax(struct nodeh **hd) | |
{ | |
struct nodeh *temp; | |
temp = *hd; | |
int max = temp->data; | |
while(temp->next != 0) | |
{ | |
if(max < temp->data) | |
max = temp->data; | |
temp = temp->next; | |
} | |
return max; | |
} | |
void display(struct nodeh **hd) | |
{ | |
struct nodeh *temp; | |
temp = *hd; | |
while(temp != NULL) | |
{ | |
printf("%d ",temp->data); | |
temp = temp->next; | |
} | |
puts(""); | |
} | |
void radix(struct nodeh **hd,int kase) | |
{ | |
int i,div,m,num,z,j; | |
div=1; | |
while(kase--) | |
{ | |
struct nodev *headv = NULL,*tempv; | |
for(i=0;i<10;i++) | |
{ | |
insertv(&headv,i); | |
} //Vertical list created | |
while(*hd != NULL) | |
{ | |
num = pop(hd); | |
z = (num/div)%10; | |
tempv = headv; | |
for(j=0;j<z;j++) | |
{ | |
tempv = tempv->link; | |
} | |
inserth(&(tempv)->head,num); | |
} | |
tempv = headv; | |
for(i=0;i<10;i++) | |
{ | |
while(tempv->head != NULL) | |
{ | |
z = pop(&(tempv)->head); | |
inserth(hd,z); | |
} | |
tempv = tempv->link; | |
} | |
div *= 10; | |
} | |
} | |
int pop(struct nodeh **hd) | |
{ | |
if(*hd == NULL) | |
return; | |
else | |
{ | |
int z; | |
z = (*hd)->data; | |
(*hd) = (*hd)->next; | |
return z; | |
} | |
} | |
int main(int argc,char *argv[]) | |
{ | |
if(argc != 2){puts("Wrong number of args");exit(1);} | |
FILE *fp; | |
struct nodev *tempv,*headv = NULL; | |
struct nodeh *main = NULL; | |
if((fp = fopen(argv[1],"r")) == NULL){puts("Can't open file");exit(1);} | |
int x,len=0,num,max,kase=0; | |
while(fscanf(fp,"%d",&num) != EOF) | |
{ | |
// printf("%d ",num); | |
inserth(&main,num); | |
len++; | |
} | |
fclose(fp); | |
max = getmax(&main); | |
while(max > 0){max=max/10;kase++;} | |
// printf("\n%d\n ",kase); | |
display(&main); | |
radix(&main,kase); | |
printf("After sorting\n"); | |
display(&main); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Work easy...!!...Play hard*/ | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
struct nodeh | |
{ | |
char str[50]; | |
struct nodeh *next; | |
}; | |
struct nodev | |
{ | |
int index; | |
struct nodeh *head; | |
struct nodev *link; | |
}; | |
char *pop(struct nodeh **); | |
void inserth(struct nodeh **hd,char *str) | |
{ | |
struct nodeh *new,*temp; | |
new = (struct nodeh *)malloc(sizeof(struct nodeh)); | |
strcpy(new->str,str); | |
new->next = NULL; | |
if(*hd == NULL) | |
{ | |
*hd = new; | |
} | |
else | |
{ | |
temp = *hd; | |
while(temp->next != NULL) | |
{ | |
temp = temp->next; | |
} | |
temp->next = new; | |
} | |
} | |
void insertv(struct nodev **hd,int i) | |
{ | |
struct nodev *new,*temp; | |
new = (struct nodev *)malloc(sizeof(struct nodev)); | |
new->index = i; | |
new->link = NULL; | |
new->head = NULL; | |
if(*hd == NULL) | |
{ | |
*hd = new; | |
} | |
else | |
{ | |
temp = *hd; | |
while(temp->link != NULL) | |
{ | |
temp = temp->link; | |
} | |
temp->link = new; | |
} | |
} | |
void display(struct nodeh **hd) | |
{ | |
struct nodeh *temp; | |
temp = *hd; | |
while(temp != NULL) | |
{ | |
printf("%s ",temp->str); | |
temp = temp->next; | |
} | |
} | |
void radix(struct nodeh **hd,int max) | |
{ | |
int i,j,div,len = max,z; | |
char ch,str[50],n[50]; | |
while(max--) | |
{ | |
struct nodev *headv = NULL,*tempv,*temp2; | |
for(i=0;i<26;i++) | |
{ | |
insertv(&headv,i); | |
} | |
while(*hd != NULL) | |
{ | |
strcpy(str,pop(hd)); | |
ch = str[len-1]; | |
if(ch >= 'a' && ch <= 'z') | |
z = ch%97; | |
if(ch >= 'A' && ch <= 'Z') | |
z = ch%65; | |
tempv = headv; | |
for(j=0;j<z;j++) | |
{ | |
tempv = tempv->link; | |
} | |
inserth(&(tempv)->head,str); | |
} | |
temp2 = headv; | |
for(i=0;i<26;i++) | |
{ | |
while(temp2->head != NULL) | |
{ | |
strcpy(n,pop(&(temp2)->head)); | |
inserth(hd,n); | |
} | |
temp2 = temp2->link; | |
} | |
len--; | |
} | |
} | |
char *pop(struct nodeh **hd) | |
{ | |
char str[50]; | |
if(*hd == NULL) | |
{ | |
return; | |
} | |
else | |
{ | |
strcpy(str,(*hd)->str); | |
(*hd) = (*hd)->next; | |
return str; | |
} | |
} | |
int main(int argc,char *argv[]) | |
{ | |
if(argc != 2){puts("Wrong number of args");exit(1);} | |
FILE *fp; | |
struct nodev *tempv,*headv = NULL; | |
struct nodeh *main = NULL,*temph; | |
if((fp = fopen(argv[1],"r")) == NULL){puts("Can't open file");exit(1);} | |
int x,len=0,num,max,kase=0; | |
char str[50]; | |
while(fscanf(fp,"%s",&str) != EOF) | |
{ | |
// printf("%s\n",str); | |
inserth(&main,str); | |
len++; | |
} | |
fclose(fp); | |
display(&main); | |
temph = main; | |
max = strlen(temph->str); | |
puts("Now given file contains..."); | |
while(temph != NULL) | |
{ | |
if(max < strlen(temph->str)) | |
{ | |
max = strlen(temph->str); | |
} | |
temph = temph->next; | |
} | |
printf("\n%d\n",max); | |
radix(&main,max); | |
display(&main); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment