Ask a question from expert

Ask now

Implementation of Linked List

5 Pages1119 Words220 Views
   

Added on  2019-09-20

Implementation of Linked List

   Added on 2019-09-20

BookmarkShareRelated Documents
Implementation of linked list #include<stdio.h>#include<conio.h>#include<stdlib.h>void insertAtBeginning(int);void insertAtEnd(int);void insertBetween(int,int,int);void display();void removeBeginning();void removeEnd();void removeSpecific(int);struct Node{ int data; struct Node *next;}*head = NULL;void main(){ int choice,value,choice1,loc1,loc2; clrscr(); while(1){ mainMenu: printf("\n\n********* MENU ************\n1. Insert\n2. Display\n3. Delete\n4. Exit\nEnter your choice: "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the value to be insert: ");scanf("%d",&value);while(1){printf("Where you want to insert: \n1. At Beginning\n2. At End\n3. Between\nEnter your choice: ");scanf("%d",&choice1);switch(choice1){ case 1: insertAtBeginning(value);break; case 2: insertAtEnd(value);break; case 3: printf("Enter the two values where you wanto insert: ");scanf("%d%d",&loc1,&loc2);insertBetween(value,loc1,loc2);break; default: printf("\nWrong Input!! Try again!!!\n\n");goto mainMenu;}goto subMenuEnd;}subMenuEnd:break; case 2: display();break;
Implementation of Linked List_1
case 3: printf("How do you want to Delete: \n1. From Beginning\n2. From End\n3. Spesific\nEnter your choice: ");scanf("%d",&choice1);switch(choice1){ case 1: removeBeginning();break; case 2: removeEnd(value);break; case 3: printf("Enter the value which you wanto delete: ");scanf("%d",&loc2);removeSpecific(loc2);break; default: printf("\nWrong Input!! Try again!!!\n\n");goto mainMenu;}break; case 4: exit(0); default: printf("\nWrong input!!! Try again!!\n\n"); } }}void insertAtBeginning(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; if(head == NULL) { newNode->next = NULL; head = newNode; } else { newNode->next = head; head = newNode; } printf("\nOne node inserted!!!\n");}void insertAtEnd(int value){ struct Node *newNode; newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = value; newNode->next = NULL; if(head == NULL)head = newNode; else { struct Node *temp = head; while(temp->next != NULL)temp = temp->next; temp->next = newNode; } printf("\nOne node inserted!!!\n");
Implementation of Linked List_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Implementation of queue using linked list.
|3
|442
|243

Implementation of Stack using Linked List
|3
|427
|344

Interview Questions
|7
|1175
|91

Data Structure - Assignment
|9
|1398
|163