You are on page 1of 10
/*Design, Develop and Implement a menu driven Program in C for the following operations on Doubly Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo a. Create a DLL of N Employees Data by using end insertion, Display the status of DLL and count the number of nodes in it c. Perform Insertion and Deletion at End of DLL 4d. Perform Insertion and Deletion at Front of DLL e. Demonstrate how this DLL can be used as Double Ended Queue. fExit*/ include include Struct node { Int sn, sl, ph; Char n{30], dp[20}, dg(20]; Struct node *next, *prev; )first=NULL,*last=NULL,"t=NULL; Int Void create() 1 ‘To(struct node*}malloc(sizeof{struct node}); Printf("Enter the serial number, Name, Department, designation, Salary, Phone number:-\n"); Scanf("%d%s%s%s%d7%d", &t->sn, t->n, t->dp, todg, &t->sl, &t->ph); tonext=t->prev=NULL; cts 1 ‘Scanned with CamScanner Void insertatend() { Create(); First=last=t; Else { Last-onext=t t->prevelast; ‘te>next=NULL; last , i Void insertatfront() { Create(); If(first==NULL) First=last=t; Else tonext=first; ‘t->preveNULL; ‘Scanned with CamScanner Void deleteatfront() Else Printf("The removed node is :- \n9id\t%s\t%s\t9%6s\t%a\t%d\n" first->sn, first->n, first->dp, first->dg, first->sl, first->ph); Free(irst); First=last=NULL; oy } Else { Printf("The removed node is :- \nvéd\t%s\t%s\t%s\t%d\t%4d\n" first->sn, first->n, first >dp, first->dg, first->sl,first->ph); Firstefirst->next; Free(first->prev); First->prev=NULL; Void deleteatend() { If(first==NULL) Printf(“List is empty.\n"); Else ‘Scanned with CamScanner H(first==NULL) Printf(“List is empty.\n”); Else Printf(“The removed node is :- \n%d\t%s\t%s\t%6s\t%d\t%4d\n",last->sn, last->n, last->dp, last->dg, last->sl, last->ph); Free(tirst); First=! © Else Printf("The removed node is :- \nvéd\t%s\t%s\t%s\t%d\t%4d\n" last->sn, last->n, last >dp, last->dg, last->sl, last->ph); Last->prev->next=NULL; Telast; Lastelast->prev; Free(t); , d Void display() { ‘Scanned with CamScanner Printf(“Total number of nodes = %d\n\n",c); Printf(“Serial number\tName\tDepartment\tDesignation\tSalary\tPhone number\n\n"); st; While(t) { Printf(“9éd\t\t3és\t%s\t\t%s\t\t%d\t%6d\n",t->sn, t->n, t>dp, todg, t>sl, t->ph); Tet-onext; , 1 Void main() { Intch, n, 1; Do { Printf(“\nMENU\n1.CREATE DLL\n2.DISPLAY\n3.INSERT AT END\n4,DELETE AT END\nS.INSERT AT FRONT\n6, DELETE AT FRONT\N7.EXIT\n"); Printf(“Enter your choice“); Scanf{"%d”,&ch); Switch(ch) { Case 1: printf{"Enter the number of employees: “); Scanf("%d",8n); For jienyie4) Insertatend(); Break; Case 2: display(); Break; ‘Scanned with CamScanner Case 3: insertatend(); Break; Case 4: deleteatendi); Break; Case 5: insertatfront(); Break; Case 6: deleteatfront(); Break; Case 7: exit(0); Default: printf("INVALID OPTION\n"); ‘Scanned with CamScanner Scanned with CamScanner Scanned with CamScanner Scanned with CamScanner Scanned with CamScanner

You might also like