LAB 7 and 8 Programs
LAB 7 and 8 Programs
Programme, Sem,
PhNo
in it
(Demonstration of stack)
e. Exit*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
int iSem,iPhNo;
};
NODEPTR fnGetNode(void);
void fnFreeNode(NODEPTR);
NODEPTR fnInsRear(NODEPTR);
NODEPTR fnDelFront(NODEPTR);
NODEPTR fnInsFront(NODEPTR);
NODEPTR fnDelRear(NODEPTR);
void fnDisplay(NODEPTR);
int main()
scanf("%d", &iNum);
for(i=0;i<iNum;i++)
first = fnInsFront(first);
for(;;)
printf("\nQUEUE OPERATIONS\n");
printf("====================");
scanf("%d",&iChoice);
switch(iChoice)
case 1:
first = fnInsFront(first);
break;
case 2:
first = fnInsRear(first);
break;
case 3: first = fnDelFront(first);
break;
break;
case 5: fnDisplay(first);
break;
case 6: exit(0);
return 0;
NODEPTR fnGetNode()
NODEPTR newborn;
if(newborn == NULL)
printf("nMemory Overflow");
exit(0);
scanf("%s",newborn->cUSN);
scanf("%s",newborn->cName);
scanf("%s", newborn->cProgram);
scanf("%d",&newborn->iSem);
return newborn;
void fnFreeNode(NODEPTR x)
free(x);
NODEPTR temp,cur;
temp = fnGetNode();
temp->link = NULL;
if(first == NULL)
return temp;
cur = first;
while(cur->link != NULL)
cur = cur->link;
cur->link = temp;
return first;
NODEPTR temp;
if(first == NULL)
return first;
}
temp = first;
first = first->link;
fnFreeNode(temp);
return first;
NODEPTR curr;
int count = 0;
if(first == NULL)
printf("\nSLL is empty\n");
return;
curr = first;
// printf("n");
printf("\nUSN\tName\tProgram\tSem\tPhone num");
while(curr != NULL)
printf("\n%s\t%s\t%s\t%d\t%d",curr->cUSN,curr->cName,curr->cProgram,curr-
>iSem,curr->iPhNo);
curr = curr->link;
count++;
}
NODEPTR fnInsFront(NODEPTR first)
NODEPTR temp;
temp = fnGetNode();
temp->link = NULL;
temp->link = first;
first = temp;
return first;
if(first == NULL)
return first;
prev = NULL;
cur = first;
if(cur->link == NULL)
fnFreeNode(cur);
return NULL;
while(cur->link != NULL)
prev = cur;
cur = cur->link;
}
prev->link = cur->link;
fnFreeNode(cur);
return first;
8. Develop 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
f. Exit
//program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
int iSSN;
int iSalary;
struct node *plink;
};
NODEPTR fnGetNode(void);
void fnFreeNode(NODEPTR);
NODEPTR fnInsRear(NODEPTR);
NODEPTR fnDelFront(NODEPTR);
NODEPTR fnInsFront(NODEPTR);
NODEPTR fnDelRear(NODEPTR);
void fnDisplay(NODEPTR);
int main()
for(i=0;i<iNum;i++)
first = fnInsRear(first);
for(;;)
printf("\nDLL OPERATIONS\n");
printf("====================");
scanf("%d",&iChoice);
switch(iChoice)
break;
break;
break;
break;
case 5: fnDisplay(first);
break;
case 6: exit(0);
return 0;
NODEPTR fnGetNode()
NODEPTR newborn;
if(newborn == NULL)
printf("\nMemory Overflow");
exit(0);
scanf("%d",&newborn->iSSN);
scanf("%s", newborn->cDept);
scanf("%s", newborn->cDesignation);
scanf("%d",&newborn->iSalary);
scanf("%s",newborn->cPhNo);
return newborn;
void fnFreeNode(NODEPTR x)
free(x);
NODEPTR temp,cur;
temp = fnGetNode();
if(first == NULL)
return temp;
cur = first;
while(cur->nlink != NULL)
cur = cur->nlink;
cur->nlink = temp;
temp->plink = cur;
return first;
NODEPTR temp;
temp = fnGetNode();
temp->nlink = first;
first = temp;
return first;
if(first == NULL)
printf("\nDLL is empty\n");
return first;
cur = first;
if(cur->nlink == NULL)
fnFreeNode(cur);
return NULL;
while(cur->nlink != NULL)
cur = cur->nlink;
}
prev = cur->plink;
prev->nlink = NULL;
fnFreeNode(cur);
return first;
NODEPTR temp;
if(first == NULL)
printf("\nDLL is empty\n");
return first;
if(first->nlink == NULL)
fnFreeNode(first);
return NULL;
temp = first;
first = first->nlink;
first->plink = NULL;
fnFreeNode(temp);
return first;
NODEPTR curr;
int count = 0;
if(first == NULL)
printf("\nDLL is empty\n");
return;
curr = first;
// printf("n");
printf("\nSSN\tName\tDept\tDesignation\tSalary\t\tPhone No");
while(curr != NULL)
curr = curr->nlink;
count++;
/*CPP*/