0% found this document useful (0 votes)
9 views9 pages

Program 8

Uploaded by

introvertb46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Program 8

Uploaded by

introvertb46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

#include<stdio.

h>

#include<stdlib.h>

Struct node

Char ssn[25], name[25], dept[10], designation[25];

Int sal;

Long int phone;

Struct node * llink;

Struct node * rlink;

};

Typedef struct node * NODE;

NODE first = NULL;

Int count = 0;

NODE create()

NODE enode;

Enode = (NODE) malloc(sizeof(struct node));

If (enode == NULL)

Printf(“\n Running out of memory “);

Exit(0);

}
Printf(“\n Enter the ssn,Name,Department,Designation,Salary,PhoneNo of
the employee: \n”);

Scanf(“%s %s %s %s %d %ld”, enode -> ssn, enode -> name, enode ->
dept, enode -> designation, & enode -> sal, & enode -> phone);

Enode -> llink = NULL;

Enode -> rlink = NULL;

Count++;

Return enode;

NODE insertfront()

NODE temp;

Temp = create();

If (first == NULL)

Return temp;

Temp -> rlink = first;

First -> llink = temp;

Return temp;

Void display()

NODE cur;

Int nodeno = 1;
Cur = first;

If (cur == NULL)

Printf(“\nNo Contents to display in DLL “);

While (cur != NULL)

Printf(“\nENode:%d|SSN:%s| |Name:%s| |Department:%s| |Designation:


%s| |Salary:%d| |Phone no:%ld|”, nodeno, cur -> ssn, cur -> name, cur ->
dept, cur -> designation, cur -> sal, cur -> phone);

Cur = cur -> rlink;

Nodeno++;

Printf(“\nNo of employee nodes is %d”, count);

NODE deletefront()

NODE temp;

If (first == NULL)

Printf(“\nDoubly Linked List is empty “);

Return NULL;

If (first -> rlink == NULL)

Printf(“\nThe employee node with the ssn:%s is deleted “, first -> ssn);

Free(first);

Count--;
Return NULL;

Temp = first;

First = first -> rlink;

Temp -> rlink = NULL;

First -> llink = NULL;

Printf(“\nThe employee node with the ssn:%s is deleted “, temp -> ssn);

Free(temp);

Count--;

Return first;

NODE insertend()

NODE cur, temp;

Temp = create();

If (first == NULL)

Return temp;

Cur = first;

While (cur -> rlink != NULL)

Cur = cur -> rlink;

}
Cur -> rlink = temp;

Temp -> llink = cur;

Return first;

NODE deleteend()

NODE prev, cur;

If (first == NULL)

Printf(“\nDoubly Linked List is empty “);

Return NULL;

If (first -> rlink == NULL)

Printf(“\nThe employee node with the ssn:%s is deleted “, first -> ssn);

Free(first);

Count--;

Return NULL;

Prev = NULL;

Cur = first;

While (cur -> rlink != NULL)

{
Prev = cur;

Cur = cur -> rlink;

Cur -> llink = NULL;

Printf(“\nThe employee node with the ssn:%s is deleted “, cur -> ssn);

Free(cur);

Prev -> rlink = NULL;

Count--;

Return first;

Void deqdemo()

Int ch;

While (1)

Printf(“\nDemo Double Ended Queue Operation “);

Printf(“\n1:InsertQueueFront\n 2: DeleteQueueFront\n
3:InsertQueueRear\n 4:DeleteQueueRear\n 5:DisplayStatus\n 6: Exit \n”);

Scanf(“%d”, & ch);

Switch (ch)

Case 1:

First = insertfront();

Break;
Case 2:

First = deletefront();

Break;

Case 3:

First = insertend();

Break;

Case 4:

First = deleteend();

Break;

Case 5:

Display();

Break;

Default:

Return;

Void main()

Int ch, I, n;

While (1)

Printf(“\n\n--------Menu--------“);

Printf(“\n1:Create DLL of Employee Nodes “);

Printf(“\n2:DisplayStatus”);

Printf(“\n3:InsertAtEnd”);
Printf(“\n4:DeleteAtEnd”);

Printf(“\n5:InsertAtFront”);

Printf(“\n6:DeleteAtFront”);

Printf(“\n7:Double Ended Queue Demo using DLL “);

Printf(“\n8:Exit \n”);

Printf(“\nPlease enter your choice: “);

Scanf(“%d”, & ch);

Switch (ch)

Case 1:

Printf(“\nEnter the no of Employees: “);

Scanf(“%d”, & n);

For (I = 1; I <= n; i++)

First = insertend();

Break;

Case 2:

Display();

Break;

Case 3:

First = insertend();

Break;

Case 4:

First = deleteend();
Break;

Case 5:

First = insertfront();

Break;

Case 6:

First = deletefront();

Break;

Case 7:

Deqdemo();

Break;

Case 8:

Exit(0);

Default:

Printf(“\nPlease Enter the valid choice “);

You might also like