Sei sulla pagina 1di 3

#include<stdio.h> #include<malloc.h> #include<stdlib.

h> struct link { int info; struct link *next; }; struct link * start; void insertb(struct link *); void insertl(struct link *); void inserte(struct link *); void create(struct link *); void display(struct link *); void count(struct link *); void main() { char ch='1'; struct link * node; node=(struct link*)malloc(sizeof(struct link)); if(node==NULL) { printf("out of memory space"); exit(0); } start=node; printf("for creation\n"); create(node); void insertb(struct link *node) { struct link *tmp; tmp=(struct link*)malloc(sizeof(struct link)); if(tmp==NULL) { printf("\n out of memory space\n"); exit(0); } tmp->next=node; printf("\n value of the 1st node:-\n "); scanf("%d",&tmp->info); start=tmp; } void inserte(struct link *node) { struct link *tmp; while(node->next!=NULL) node=node->next; tmp=(struct link*)malloc(sizeof(struct link)); if(tmp==NULL) { printf("\n out of memory space\n"); exit(0); } tmp->next=NULL; node->next=tmp; printf("\n value of the last node:-\n "); scanf("%d",&tmp->info);

} void insertl(struct link *node) { int loc,c=0,i=1; struct link *node1,*curr,*pre; printf("ntr location at which node will be inserted:-\n"); scanf("%d",&loc); c=count(node); if(loc > c) { printf("\n invalid location"); return; } node1=(struct link*)malloc(sizeof(struct link)); if(node1==NULL) { printf("out of memory space"); exit(0); } while(i<loc) { pre=curr; curr=curr->next; i++; } printf("value at %d location is:",loc); scanf("%d",&node1->info); if(loc==1) start=node1; else { node1->next=pre->next; pre->next=node1; }} void display(struct link * node) { if(node==NULL) { printf("\n empty list"); return; } printf("\n nodes are:-"); while(node!=NULL) { printf(" %d ",node->info); node=node->next; } printf("\n"); } void create(struct link * node) { char ch; int i=1; printf("enter value for %d node:",i); scanf("%d", &node->info);

node->next=NULL; i++; printf("press 'n' to quit and any other value to continue"); ch=getchar(); while(ch!='n') { node->next=(struct link*)malloc(sizeof(struct link)); if(node->next==NULL) { printf("\n out of memory space"); exit(0); } node=node->next; printf("ntr the value for %d node",i); scanf("%d",&node->info); node->next=NULL; i++; printf("press 'n' to quit and any value to continue:"); ch=getchar(); } }

Potrebbero piacerti anche