#include #include typedef struct Node { int data; struct Node *next; }node; node *head= NULL, *temp,*start ,*first ,*last,*trail,*any ; void Create(int num) //3 { int i ; printf("Give input \n"); for(i= 0 ;i data); if(head==NULL) { head = temp; } else { trail->next = temp; } trail = temp ; } temp->next = NULL; printf("All node create successfully\n\n"); } void display() { start = head; while(start != NULL) { printf("%d->",start->data); start = start ->next ; } printf("NULL\n\n"); } void FirstInsert() { //first = head; temp = (struct Node*) malloc(sizeof(node)); first = temp; printf("Enter a value for first insert: "); scanf("%d", &temp->data); if(head == NULL) { head = first; first->next = NULL ; } else { first->next = head; head = first ; } printf("First insert successfully\n\n"); } void LastInsert() { temp = (struct Node*) malloc(sizeof(node)); last= head ; printf("Enter Enter a value for last insert: "); scanf("%d", &temp->data); while(last->next != NULL) { last = last->next; // last->next=NULL; } last->next = temp ; temp->next=NULL; } void AnyInsert(int value) { any = head ; int flag = 0; while(1) { if(any->data == value) { temp = (struct Node*) malloc(sizeof(node)); printf("Enter a value for any position insert: "); scanf("%d", &temp->data); temp->next= any->next; any->next= temp ; printf("Any position insert successfully\n\n"); break ; } else{ if(any->next==NULL) { flag =1 ; printf("data not found "); break; return flag; } any = any->next ; } } } void update(int value) { any = head ; while(1) { if(any->data == value) { printf("Enter a new value\n"); scanf("%d", &any->data); printf("update is successfully\n\n"); break ; } else{ if(any->next==NULL) { printf("data not found "); break; } any = any->next ; } } } void search(int value) //10 { any = head ; while(1) { if(any->data == value) { printf("data is found \n\n"); break ; } else{ if(any->next==NULL) { printf("data not found\n "); break; } any = any->next ; } } } void delete(int value)//1 { start=head; while(1){ if(head->data==value) //if we want to delete first number { head = head->next ; break; } if(start->data == value) { last->next = last ->next->next; break; }else{ if(start->next==NULL) { printf("data is not found"); break; } last= start; start = start->next ; } } } int main() { int choich, val , num,ex; do { printf("1. Create \n2.First Insert \n3. Last Insert\n4. Any position Insert\n5.Update\n6. Delete\n7. Search\n0. Exit\n"); scanf("%d", &choich); switch(choich) { case 1 : printf("how many node u want to create: \n"); scanf("%d",&num); Create(num); display(); break; case 2 : FirstInsert(); display(); break; case 3 : LastInsert(); display(); break; case 4 : printf(" Enter a number after u want to insert\n"); scanf("%d",&val); AnyInsert(val); display(); break; case 5: printf("Enter the number which you want to update the value?\n"); scanf("%d",&val); update(val); display(); break; case 6: printf("Enter the number which you want to delete the value?\n"); scanf("%d",&val); delete(val); display(); break; case 7: printf("Enter the number which you want to search the value?\n"); scanf("%d",&val); search(val); //display(); break; default: printf("pls give right input"); } // printf("clik 0 for exit"); // scanf("%d",&ex); } while(choich != 0); return 0; }