Implementation of Linked List

Added on - 20 Sep 2019

  • 5

    Pages

  • 1119

    Words

  • 95

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 2 of 5 pages
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. AtEnd\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 wantoinsert: ");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;
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 wantodelete: ");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");
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document