Created
January 12, 2014 13:01
-
-
Save mukeshkdangi/8384325 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include<stdio.h> | |
#include<malloc.h> | |
#include<conio.h> | |
#include<stdlib.h> | |
struct dlist{ | |
int info; | |
struct dlist *next; | |
struct dlist *prev; | |
}; | |
struct dlist *start; | |
void deletenode(struct dlist *); | |
void insertbynode(struct dlist *); | |
void insert(struct dlist *); | |
int count(struct dlist *); | |
void creatdlist(struct dlist *); | |
void display(struct dlist *); | |
int main(){ | |
int e,i,n,c; | |
printf("\nDoubly link list ....."); | |
struct dlist *node; | |
//clrscr(); | |
node=(struct dlist *)malloc(sizeof( struct dlist )); | |
start=node; | |
creatdlist(node); | |
printf("\n1.Insert.\n2.displa\3.Quit\n4.Count node\n5.insert by node\n6.delete node"); | |
fflush(stdin); | |
scanf("%d",&c); | |
while(c!=3){ | |
switch(c){ | |
case 1: | |
insert(node); | |
node=start; | |
break; | |
case 2: | |
display(node); | |
break; | |
case 3: | |
break; | |
case 4: | |
e=count(node); | |
printf("\nTotal number of node :%d",e); | |
break; | |
case 5: | |
insertbynode(node); | |
node; | |
break; | |
case 6: | |
deletenode(node); | |
break; | |
} | |
printf("\n1.Insert.\n2.displa\3.Quit\n4.Count node\n5.insert by node\n6.delete node"); | |
fflush(stdin); | |
scanf("%d",&c); | |
} | |
return 0; | |
} | |
void creatdlist(struct dlist *node){ | |
int i=1; | |
char ch; | |
node=start; | |
struct dlist *curr; | |
printf("\nENter %d node value :",i++); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=start; | |
node->prev=start; | |
printf("\nEnter n ->quit :"); | |
fflush(stdin); | |
scanf("%c",&ch); | |
while(ch!='n'){ | |
curr=(struct dlist *)malloc(sizeof(struct dlist )); | |
node->next=curr; | |
curr->prev=node; | |
node=node->next; | |
printf("\nEnter the %d node value:",i++); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=start; | |
start->prev=node; | |
printf("\nEnter n ->quit:"); | |
fflush(stdin); | |
scanf("%c",&ch); | |
} | |
} | |
void display(struct dlist *node){ | |
struct dlist *t; | |
t=node; | |
printf("%d->",node->info); | |
node=node->next; | |
while(node!=t){ | |
printf("%d->",node->info); | |
node=node->next; | |
} | |
} | |
void insert(struct dlist *node){ | |
int i=1,pos=0; | |
struct dlist *pprev=start,*curr=start; | |
int t=count(node); | |
printf("\nEnter the location of node :"); | |
fflush(stdin); | |
scanf("%d",&pos); | |
if(pos>t){ | |
printf("\nOut of memory:"); | |
} | |
else{ | |
curr=(struct dlist*)malloc(sizeof(struct dlist )); | |
printf("\nEnter the value of node:"); | |
fflush(stdin); | |
scanf("%d",&curr->info); | |
if(pos==1){ | |
curr->next=node; | |
node->prev=curr; | |
curr->prev=NULL; | |
//node=curr; | |
start =curr; | |
}else{ | |
while(i!=pos){ | |
i++; | |
pprev=node; | |
node=node->next; | |
} | |
pprev->next=curr; | |
curr->prev=pprev; | |
curr->next=node; | |
node->prev=curr; | |
node=curr; | |
} | |
} | |
} | |
int count(struct dlist *node){ | |
int j=0; | |
while(node!=NULL){ | |
node=node->next; | |
j++; | |
} | |
return j; | |
} | |
void insertbynode(struct dlist *node){ | |
int i=1,val,r; | |
r=count(node); | |
struct dlist *pprev,*curr; | |
printf("\nEnter the node value after u want to enter the new node :"); | |
scanf("%d",&val); | |
curr=(struct dlist *)malloc(sizeof(struct dlist )); | |
while(val!=node->info){ | |
pprev=node; | |
node=node->next; | |
i++; | |
} | |
if(i>r){ | |
printf("\nNode doen't exist :"); | |
return ; | |
}else{ | |
curr=(struct dlist *)malloc(sizeof(struct dlist )); | |
printf("\nEnter the new node value :"); | |
fflush(stdin); | |
scanf("%d",&curr->info); | |
pprev->next=curr; | |
curr->prev=pprev; | |
curr->next=node; | |
node->prev=curr; | |
node=curr; | |
} | |
} | |
void deletenode(struct dlist *node){ | |
int i=1,pos; | |
struct dlist *pprev,*curr,*temp; | |
printf("\nEnter the location of node which u want to delete:"); | |
fflush(stdin); | |
scanf("%d",&pos); | |
int t=count(node); | |
if(pos>t){ | |
printf("\nCan't be deleteed:"); | |
} | |
else{ | |
while(i!=pos){ | |
pprev=node; | |
node=node->next; | |
i++; | |
} | |
temp=node; | |
pprev->next=node->next; | |
node->next->prev=pprev; | |
free(temp); | |
node=node->next; | |
} | |
} |
This file contains hidden or 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
#include<stdio.h> | |
#include<malloc.h> | |
struct slist{ | |
int info; | |
struct slist *next; | |
}; | |
int nn=0; | |
struct slist *start=NULL; | |
void createlist(struct slist * ); | |
void display(struct slist * ); | |
void deletnode(struct slist * ); | |
void insertnode(struct slist * ); | |
int count(struct slist * ); | |
void reverse(struct slist *); | |
int main(){ | |
int i,j,ch=0,n,t=0; | |
struct slist *node=NULL; | |
printf("\nSingle LINK LIST >>>>>>>>>>>>>>"); | |
node=(struct slist *)malloc(sizeof(struct slist)); | |
createlist(node); | |
start =node; | |
printf("\nEnter Your Choice.ss.,,,,,....\n1.Insert.\2ndelete\n3.dispaly"); | |
fflush(stdin); | |
scanf("%d",&ch); | |
while(ch!=4){ | |
switch(ch){ | |
case 1: insertnode(node); | |
break; | |
case 2:deletnode(node); | |
break; | |
case 3:display(node); | |
case 4:break; | |
case 5:t=count(node); | |
printf("\n node number %d node:",t); | |
break; | |
case 6:reverse(node); | |
break; | |
} | |
printf("\n1.Insert\n2.Delete\n3.Display\n4.Quit\n5.count node\n6.reverse:"); | |
fflush(stdin); | |
scanf("%d",&ch); | |
} | |
return 0; | |
} | |
void createlist(struct slist *node){ | |
int i=0; | |
char ch='y'; | |
printf("\nEnter %d node value:",i++); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=start; | |
while(ch!='n'){ | |
node->next=(struct slist *)malloc(sizeof(struct slist )); | |
node=node->next; | |
printf("\nEnter %d node value: ",i++); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=start; | |
printf("do you want insert more values:?y/n"); | |
fflush(stdin); | |
scanf("%c",&ch); | |
} | |
} | |
void display(struct slist *node){ | |
node=start; | |
struct slist *t=start; | |
//node=node->next; | |
printf("\nIn display :"); | |
do{ | |
printf("%d->",node->info); | |
node=node->next; | |
}while(node!=t); | |
//printf("=-%d",node->next->info); | |
} | |
void insertnode(struct slist *node){ | |
int pos=0,i=1; | |
struct slist *prev,*curr,*newnode; | |
printf("\nEnter the location where u wAANT TO insert:"); | |
fflush(stdin); | |
scanf("%d",&pos); | |
curr=prev=start; | |
newnode=(struct slist *)malloc(sizeof(struct slist)); | |
printf("\nEnter the new node data:"); | |
fflush(stdin); | |
scanf("%d",&newnode->info); | |
if(pos==1){ | |
prev=start; | |
newnode->next=prev; | |
start=newnode; | |
} | |
else{ | |
while(i!=pos){ | |
prev=curr; | |
curr=curr->next; | |
i++; | |
} | |
if(i==count(node)){ | |
curr->next=newnode; | |
newnode->next=NULL; | |
} | |
else{ | |
prev->next=newnode; | |
newnode->next=curr; | |
} | |
} | |
} | |
int count(struct slist *node){ | |
nn=0; | |
node=start; | |
while(node!=NULL){ | |
node=node->next; | |
nn++; | |
} | |
return nn; | |
//printf("\n\t%d node are present :",n); | |
} | |
void deletnode(struct slist *node){ | |
int i=0,n,pos=0; | |
struct slist *prev,*curr,*temp; | |
prev=curr=start; | |
printf("\nEnter the pos which u want to delete:"); | |
fflush(stdin); | |
scanf("%d",&pos); | |
if(pos>count(node)||count(node)==0){ | |
printf("canot delte :"); | |
return ; | |
} | |
if(pos==1){ | |
prev=start; | |
start=start->next; | |
free(prev); | |
} | |
else if(pos==count(node)){ | |
//curr=prev=start; | |
printf("\n count ==pos :"); | |
while(curr->next!=NULL){ | |
prev=curr; | |
curr=curr->next; | |
} | |
printf("%d %d",prev->info,curr->info); | |
//temp=curr; | |
prev->next=NULL; | |
free(curr); | |
} | |
else{ | |
//prev=curr=start; | |
while(i!=pos){ | |
prev=curr; | |
curr=curr->next; | |
i++; | |
} | |
temp=curr; | |
prev->next=curr->next; | |
//free(temp); | |
free(temp); | |
} | |
} | |
void reverse(struct slist *node){ | |
int i=0,k; | |
printf("\nEnter the value of k:"); | |
fflush(stdin); | |
scanf("%d",&k); | |
struct slist *prev,*curr,*ptr,*h1,*h2,*t1,*t2,*temp; | |
/*curr=start; | |
prev=curr->next; | |
curr->next=NULL; | |
while(prev->next!=NULL){ | |
ptr=prev->next; | |
prev->next=curr; | |
curr=prev; | |
prev=ptr; | |
} | |
prev->next=curr; | |
start=prev; | |
display(node);*/ | |
printf("\nHere is required one ::::"); | |
curr=start; | |
//while(i!=k){ | |
prev=curr->next; | |
curr->next=NULL; | |
temp=start; | |
while(++i!=k){ | |
temp=temp->next; | |
} | |
while(prev->next!=temp){ | |
ptr=prev->next; | |
prev->next=curr; | |
curr=prev; | |
prev=ptr; | |
} | |
prev->next=curr; | |
h1=prev; | |
display(h1); | |
curr=prev->next; | |
prev=curr->next; | |
curr->next=NULL; | |
while(prev->next!=NULL){ | |
ptr=prev->next; | |
prev->next=curr; | |
curr=prev; | |
prev=ptr; | |
} | |
prev->next=curr; | |
start=prev; | |
display(start); | |
} |
This file contains hidden or 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
#include<stdio.h> | |
#include<malloc.h> | |
#include<conio.h> | |
#include<stdlib.h> | |
struct slist { | |
int info; | |
struct slist *next; | |
}; | |
struct slist *start=NULL; | |
void createlist(struct slist *); | |
void insert(struct slist *); | |
int count(struct slist *); | |
void display(struct slist *); | |
void deletenode(struct slist *); | |
void deletebyvalue(struct slist *); | |
void search(struct slist *); | |
void sorting(struct slist *); | |
int main(){ | |
int c=0,t; | |
char ch; | |
struct slist *node; | |
printf("\nSingle Link List ...."); | |
node=(struct slist *)malloc(sizeof(struct slist *)); | |
//printf("\n"); | |
start=node; | |
createlist(node); | |
//node=start; | |
while(c!=4){ | |
switch(c){ | |
case 1: | |
insert(node); | |
node=start; | |
break; | |
case 2: | |
//node=start; | |
display(node); | |
break; | |
case 3: | |
t=count(node); | |
printf("\nTotal Number of node in list is :%d",t); | |
break; | |
case 5: | |
deletenode(node); | |
case 6: | |
deletebyvalue(node); | |
break; | |
case 7: | |
search(node); | |
break; | |
case 8:sorting(node); | |
break; | |
case 4:break; | |
default: | |
printf("\nEnter correct numeber:"); | |
break; | |
} | |
printf("\nEnter your choice ....\n1.Insert\n2.Dispaly\n3.count\n5.delete node \n6.delete node by value \n7. Search node \n8.sorting .\n4.Quit"); | |
scanf("%d",&c); | |
} | |
//printf(""); | |
return 0; | |
} | |
void createlist(struct slist *node ){ | |
//struct slist *temp; | |
int i=0; | |
char ch; | |
printf("\nCreating neww link list ..."); | |
printf("\nEnter the %d node value...",i); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=NULL; | |
i++; | |
printf("\nPress <n> for quit and any other char for continue:"); | |
fflush(stdin); | |
scanf("%c",&ch); | |
while(ch!='n'){ | |
node->next=(struct slist *)malloc(sizeof(struct slist )); | |
node=node->next; | |
printf("\nEnter %d node value:",i++); | |
fflush(stdin); | |
scanf("%d",&node->info); | |
node->next=NULL; | |
printf("\nPress n->quit "); | |
fflush(stdin); | |
scanf("%c",&ch); | |
} | |
//node=start; | |
//printf("\n%d values inserted .....with.%d",i,node->info); | |
} | |
int count(struct slist *node){ | |
int j=0; | |
//node=start; | |
while(node!=NULL){ | |
node=node->next; | |
j++; | |
} | |
return j; | |
} | |
void insert(struct slist *node){ | |
struct slist *prev,*curr; | |
int pos,i,j=1; | |
curr=(struct slist *)malloc(sizeof(struct slist *)); | |
printf("\nEnter the new elemrnt postion :"); | |
scanf("%d",&pos); | |
i=count(node); | |
if(pos>i){ | |
printf("\nCanot be added:"); | |
return;} | |
else{ | |
while(j<pos){ | |
prev=node; | |
node=node->next; | |
j++; | |
} | |
printf("\nEnter the value:for-%d postion ",pos); | |
scanf("%d",&curr->info); | |
if(i==1){ | |
start=curr; | |
} | |
else{ | |
prev->next=curr; | |
curr->next=node; | |
} | |
} | |
//node=start; | |
} | |
void display(struct slist *node){ | |
//printf("\nIN diaply fuction...%d",node->info); | |
node=start; | |
while(node != NULL){ | |
printf("%d->",node->info); | |
node=node->next; | |
} | |
} | |
void deletenode(struct slist *node){ | |
struct slist *temp,*prev,*curr; | |
int pos,i=1,r; | |
r=count(node); | |
printf("\nEnter the location to which u want to delete node :"); | |
scanf("%d",&pos); | |
if(pos>r){ | |
printf("\nCanot delete: out of order "); | |
} | |
else{ | |
//node=start; | |
while(i<pos){ | |
prev=node; | |
node=node->next; | |
i++; | |
} | |
if(pos==1){ | |
start=node->next; | |
} | |
else{ | |
prev->next=node->next; | |
free(node); | |
} | |
} | |
} | |
void deletebyvalue(struct slist *node){ | |
int i=1,val; | |
struct slist *prev,*curr; | |
printf("\nEnter the value which u want to delete:"); | |
scanf("%d",&val); | |
while(node->info!=val){ | |
i++; | |
prev=node; | |
node=node->next; | |
} | |
prev->next=node->next; | |
free(node); | |
} | |
void search(struct slist *node){ | |
int i=1,val; | |
int t=count(node); | |
struct slist *prev,*curr; | |
printf("\nEnter the value which u want to search :"); | |
scanf("%d",&val); | |
while(node->info!=val){ | |
i++; | |
prev=node; | |
node=node->next; | |
} | |
if(i!=t){ | |
printf("\nElement fount @%d",i); | |
}else if(i==t){ | |
printf("nElenmet not found :"); | |
} | |
} | |
void sorting(struct slist *node) | |
{ | |
int i; | |
struct slist *prev,*curr,*temp; | |
for(curr=node;curr->next!=NULL;curr=curr->next){ | |
for(prev=curr;prev->next!=NULL;prev=prev->next){ | |
if(curr->info>prev->info){ | |
i=prev->info; | |
prev->info=curr->info; | |
curr->info=i; | |
} | |
} | |
} | |
} |
This file contains hidden or 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
#include<stdio.h> | |
int main(){ | |
int i=0,j,n,rem=0,qt=0,num[20]; | |
while(1){ | |
printf("\nEnter number n :"); | |
scanf("%d",&n); | |
qt=n; | |
while(qt!=0){ | |
num[i++]=qt%8; | |
qt=qt/8; | |
} | |
for(j=i-1;j>=0;j--){ | |
printf("%d",num[j]); | |
num[j]=0; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment