Sie sind auf Seite 1von 9

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

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

Single Linked List

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

Single Linked List

Date: } return s; } int menu() { int ch; printf("\n Menu...\n");

Single Linked List

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

Date: scanf("%d", &m); insert(l,m,n); printf("\n List is..."); display(l); break; case 3: printf("\n Enter element to be search..."); scanf("%d", &n); search(l,n); break; case 4: printf("\n Enter position to be delete..."); scanf("%d",&n); deletep(l,n); printf("\n List is..."); display(l); break; case 5: printf("\n Enter element to be delete..."); scanf("%d", &n); deletee(l,n); printf("\n List is..."); display(l); break; case 6: printf("\n Enter Kth position to be find..."); scanf("%d", &n);

Single Linked List

printf("The element in that position is%d",findk(l,n)); break; case 7: printf("\n List is..."); display(l); break; case 8: printf("\n Original list is..."); display(l); printf("\n Reverse of the list is..."); Lakkireddy balireddy college of engineering 5

Date: q=reverse(q,l); display(q); break; case 0: exit(0); default: printf("\n Invalid choice..."); } printf("\n press any key to continue..."); getch(); op=menu(); }while(1); }

Single Linked List

Lakkireddy balireddy college of engineering

Date:

Single Linked List

Lakkireddy balireddy college of engineering

Date:

Single Linked List

Lakkireddy balireddy college of engineering

Date:

Single Linked List

Lakkireddy balireddy college of engineering

Das könnte Ihnen auch gefallen