Date: #include<stdio.h> #include<conio.h> #include<alloc.

h> typedef int element; struct node { element eno; struct node *next; }; typedef struct node *list; list createlist() { list l; l=(list)malloc(sizeof(struct node)); l->next=NULL; return l; } void append(list l,int x) { list t; while(l->next!=NULL) l=l->next; t=createlist(); t->eno=x; t->next=NULL; l->next=t; } void insert(list l,int p, element x) { list t,q; int i; Lakkireddy balireddy college of engineering

Single Linked List

1

} int search(list l..i++) q=q->next... } q=q->next.i++) q=q->next. t->next=q->next. return p. for(i=1. t->eno=x.%d".element x) { int p=1. return -1. } if(q->eno!=x) printf("\n Not exist.q=l. t=q->next. Lakkireddy balireddy college of engineering Single Linked List 2 . q->next=t. t=createlist().i>p.p)..").i<p. int i. } void deletep(list l.Date: q=l. list q=l.int p) { list t. free(t). while(q->next!=NULL) { if(q->next->eno==x) { printf("\n Element found at position. p++. for(i=1. q->next=t->next.

s->next=t.i<k. t->eno=q->next->eno.q->next!=NULL.p). list q=l. } list reverse(list s.int k) { int i.q->next!=NULL.p). for(q=l. t->next=s->next. if(p==-1) printf("\n Number not found. } element findk(list l.q. for(q=l.q=q->next) printf("%d-->".m..q=q->next) { t=createlist(). } void display(list l) { list q=l.q->next->eno). Lakkireddy balireddy college of engineering Single Linked List 3 . return(q->next->eno). else deletep(l.list l) { list t.Date: } void deletee(list l. for(i=1."). int p) { int x. p=search(l.i++) q=q->next..

int n. case 2: printf("\n Enter element to be insert. Insert at position \n\t 3. Lakkireddy balireddy college of engineering 4 .").&ch)."). do { switch(op) { case 1: printf("\n Enter element to be append....q.&n). clrscr().. printf("\n\n Enter ur choice. q=createlist(). l=createlist(). break. Exit"). Search \n\t 4.. scanf("%d"..\n")... op=menu()... append(l. } int menu() { int ch. Finding Kth position \n\t 7.&n).op. return ch.m. printf("\n Menu. Reverse of list \n\t 0. Single Linked List printf(" \n\t 1. scanf("%d". Appened \n\t 2.Date: } return s.n). Delete element \n\t 6. Delete position \n\t 5. printf("\n Enter position. Display list \n\t 8."). scanf("%d"."). } void main() { list l.

&m)..&n)..."). break..findk(l.. printf("\n List is..m. deletee(l. break. case 4: printf("\n Enter position to be delete."). display(l). search(l. break. Single Linked List printf("The element in that position is…%d"..n)). break..n). break. case 7: printf("\n List is. printf("\n List is. insert(l. &n). scanf("%d".n). printf("\n List is.").. display(l). printf("\n Reverse of the list is.n).").n). display(l)."). deletep(l. break. &n). display(l).")..")... case 3: printf("\n Enter element to be search. display(l).. &n). Lakkireddy balireddy college of engineering 5 . case 5: printf("\n Enter element to be delete.. case 6: printf("\n Enter Kth position to be find... scanf("%d". scanf("%d". case 8: printf("\n Original list is...")...")."). scanf("%d".Date: scanf("%d".

. } printf("\n press any key to continue. } Single Linked List Lakkireddy balireddy college of engineering 6 .l). break. case 0: exit(0).. default: printf("\n Invalid choice. getch()..").Date: q=reverse(q. display(q). }while(1)."). op=menu()..

Date: Single Linked List Lakkireddy balireddy college of engineering 7 .

Date: Single Linked List Lakkireddy balireddy college of engineering 8 .

Date: Single Linked List Lakkireddy balireddy college of engineering 9 .

Sign up to vote on this title
UsefulNot useful