Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

#include<stdio.

h> struct node { int no; struct node*next; }*start=NULL; int main() { int ch; do { printf("\n 1:creat\n2:instart\n3:inlast\n4:inafter\n5:delstart\n6:delend\n7:delgiven\n8:display\n9:exit"); printf("\n enter ur ch:"); scanf("%d",&ch); switch(ch) { } creat() { struct node *newnode,*ptr; char c; do { newnode=(struct node*)malloc(sizeof(struct node)); printf("\n enter the ele:"); scanf("%d",&newnode->no); newnode->next=NULL; if(start==NULL) { start=newnode; newnode->next=newnode; } else { ptr=start; while(ptr->next!=start) { ptr=ptr->next; } ptr->next=newnode;

} newnode->next=start; printf("\ndo u want enter the ele:"); getchar(); scanf("%c",&c); }while('y'==c); } display() { struct node *ptr; ptr=start; while(ptr->next!=start) { //ptr=ptr->next; printf("\n%d",ptr->no); ptr=ptr->next; } if(ptr->next==start) printf("\n%d",ptr->no); } instart() { struct node *newnode,*ptr; newnode=(struct node*)malloc(sizeof(struct node)); printf("\nenter the ele at start:"); scanf("%d",&newnode->no); newnode->next=NULL; if(start==NULL) { start=newnode; newnode->next=newnode; } else { ptr=start; while(ptr->next!=start) { ptr=ptr->next; } newnode->next=start; start=newnode;

ptr->next=start; } } inlast() { struct node *newnode,*ptr; char c; do { newnode=(struct node*)malloc(sizeof(struct node)); printf("\n enter the ele:"); scanf("%d",&newnode->no); newnode->next=NULL; if(start==NULL) { start=newnode; newnode->next=newnode; } else { ptr=start; while(ptr->next!=start) { ptr=ptr->next; } ptr->next=newnode; } newnode->next=start; printf("\ndo u want enter the ele:"); getchar(); scanf("%c",&c); }while('y'==c); } inafter() { struct node *newnode,*ptr; int n; newnode=(struct node*)malloc(sizeof(struct node)); printf("\enter the ele which u want to insert:"); scanf("%d",&newnode->no); printf("nenter the ele at after:");

// //

scanf("%d",&n); newnode->no=n; newnode->next=NULL; ptr=start; while((ptr->no)!=n&&(ptr!=NULL)) ptr=ptr->next;

newnode->next=ptr->next; ptr->next=newnode; } delstart() { struct node *newnode,*ptr; if(start==NULL) { printf("\n list is empty"); } else { ptr=start; printf("\n%d",ptr->no); if(ptr->next==start) { start=NULL; } else { while(ptr->next!=start) ptr=ptr->next; start=start->next; ptr->next=start; } } // free(ptr);

} delend() { struct node *newnode,*ptr,*preptr; if(start==NULL)

{ printf("\n list is empty"); } else { ptr=start; // printf("\n%d",ptr->no); if(ptr->next==start) { start=NULL; } else { while(ptr->next!=start) { preptr=ptr; ptr=ptr->next; } } printf("\n%d",ptr->no); preptr->next=start; } } delgiven() { struct node *preptr,*ptr; int n; ptr=start; printf("\n enter the no which u want to delet:"); scanf("%d",&n); while(ptr->no!=n) { preptr=ptr; ptr=ptr->next; } preptr->next=ptr->next; free(ptr); }

You might also like