#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int iSSN;
char cName[30],cDept[10],cDesignation[30],cPhNo[11];
int iSalary;
struct node *plink;
struct node *nlink;
};
typedef struct node *NODEPTR;
NODEPTR fnGetNode(void);
void fnFreeNode(NODEPTR);
NODEPTR fnInsRear(NODEPTR);
NODEPTR fnDelFront(NODEPTR);
NODEPTR fnInsFront(NODEPTR);
NODEPTR fnDelRear(NODEPTR);
void fnDisplay(NODEPTR);
int main()
{
NODEPTR first=NULL;
int iChoice,iNum,i;
printf("\n Enter the number of Employees N:"); scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:\n",i
+1); first=fnInsRear(first);
}
for(;;)
{
printf("\n DLL OPERATIONS\n"); printf("\n 1. Insert Rear \n 2. Delete Front\n 3. Insert Front \n 4. Delete Rear \n 5. Display \n 6. Exit \n"); printf("\n Enter your choice\n"); printf("\n Enter the number of Employees N:"); scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:scanf("%d
",&iChoice); switch(iChoice)
{
case 1:
first=fnInsRear(first);
break;
case 2:
first=fnDelFront(first);
break;
case 3:
first=fnInsFront(first);
break;
case 4:
first=fnDelRear(first);
break;
case 5:
fnDisplay(first);
break;
case 6:
exit(0);
}
}
return 0;
}
NODEPTR fnGetNode()
{
NODEPTR newborn;
newborn=(NODEPTR)malloc(sizeof(struct node));
if(newborn==NULL)
{
printf("n Memory overflow");
exit(0);
}
printf("\n Enter SSN:");
scanf("%d",&newborn->iSSN);
printf("\n Enter name:");
scanf("%s",newborn->cName);
printf("\n enter department:");
scanf("%s",newborn->cDept);
printf("\n Enter designation:");
scanf("%s",newborn->cDesignation);
printf("\n Enter salary:");
scanf("%d",&newborn->iSalary);
printf("\n Enter Phone No:");
scanf("%s",newborn->cPhNo);
return newborn;
}
void fnFreeNode(NODEPTR x)
{
free(x);
}
NODEPTR fnInsRear(NODEPTR firprintf("\n Enter SSN:");
scanf("%d",&newborn->iSSN);
printf("\n Enter name:");
scanf("%s",newborn->cName);
printf("\n enter department:");
scanf("%s",newborn->cDept);
printf("\n Enter designation:");
scanf("%s",newborn->cDesignation);
printf("\n Enter salary:");
scanf("%d",&newborn->iSalary);
printf("\n Enter Phone No:");
scanf("%s",newborn->cPhNo);st)
{
NODEPTR temp,cur;
temp=fnGetNode();
temp->plink=temp->nlink=NULL;
if(first==NULL)
return temp;
cur=first;
while(cur->nlink!=NULL)
{
cur=cur->nlink;
}
cur->nlink=temp;
temp->plink=cur;
return first;
}
NODEPTR fnInsFront(NODEPTR first)
{
NODEPTR temp;
temp=fnGetNode();
temp->plink=temp->nlink=NULL;
temp->nlink=first;
first=temp;
return first;
}
NODEPTR fnDelRear(NODEPTR first)
{
NODEPTR cur,prev;
if(first==NULL)
{
printf("\nDLL is
empty\n
"); return first;
}
cur=first;
if(cur->nlink==NULL)
{
printf("\n Node deleted for %s\n",cur->cName);
fnFreeNode(cur);
return NULL;
}
while(cur->nlink!=NULL)
{
cur=cur->nlink;
}
prev=cur->plink;
prev->nlink=NULL;
printf("\n Node deleted for %s\n",cur->cName);
fnFreeNode(cur);
return first;
}
NODEPTR fnDelFront(NODEPTR first)
{
NODEPTR temp;
if(first==NULL)
{
printf("\n DLL is
empty\n
"); return first;
}
if(first->nlink==NULL)
{
printf("\n Node deleted for %s\n", first->cName);
fnFreeNode(first);
return NULL;
}
temp=first;
first=first->nlink;
first->plink=NULL;
printf("\n Node deleted for %s\n",temp->cName);
fnFreeNode(temp);
return first;
}
void fnDisplay(NODEPTR first)
{
NODEPTR curr;
int count=0;
if(first==NULL)
{
printf("\n DLL is
empty\n
"); return;
}
printf("\n The contents of DLL are:\n");
currprintf("\n Enter the number of Employees N:");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:=first;
printf("\n SSN \t Name\tDept\tDesignation\tSalary\tPhone No"); while(curr!=NULL)
{
printf("\n%-5d\t%s\t%s\t%s\t%-7d\t%-11s",cur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mlyc3Q7CmZpcnN0PWZpcnN0LT5ubGluazsKZmlyc3QtPnBsaW5rPU5VTEw7CnByaW50ZigiXG4gTm9kZSBkZWxldGVkIGZvciAlc1xuIix0ZW1wLT5jTmFtZSk7CmZuRnJlZU5vZGUodGVtcCk7CnJldHVybiBmaXJzdDsKfQp2b2lkIGZuRGlzcGxheShOT0RFUFRSIGZpcnN0KQp7Ck5PREVQVFIgY3VycjsKaW50IGNvdW50PTA7CmlmKGZpcnN0PT1OVUxMKQp7CnByaW50ZigiXG4gRExMIGlzIGVtcHR5XG4iKTsKcmV0dXJuOwp9CnByaW50ZigiXG4gVGhlIGNvbnRlbnRzIG9mIERMTCBhcmU6XG4iKTsKY3VycnByaW50ZigiXG4gRW50ZXIgdGhlIG51bWJlciBvZiBFbXBsb3llZXMgTjoiKTsKc2NhbmYoIiVkIiwmaU51bSk7CmZvcihpPTA7aTxpTnVtO2krKykKewpwcmludGYoIlxuIEVudGVyIERhdGEgZm9yIG5vZGUgJWQ6PWZpcnN0OwpwcmludGYoIlxuIik7CnByaW50ZigiXG4gU1NOIFx0IE5hbWVcdERlcHRcdERlc2lnbmF0aW9uXHRTYWxhcnlcdFBob25lIE5vIik7CndoaWxlKGN1cnIhPU5VTEwpCnsKcHJpbnRmKCJcbiUtNWRcdCVzXHQlc1x0JXNcdCUtN2RcdCUtMTFzIixjdXJyLT5pU1NOLGN1cnItPmNOYW1lLGN1cnItPmNEZXB0LGN1cnItPmNEZXNpZ25hdGlvbixjdXJyLT5pU2FsYXJ5LGN1cnItPmNQaE5vKTsKY3Vycj1jdXJyLT5ubGluazsKY291bnQrKzsKfQpwcmludGYoIlxuXG5ETEwgaGFzICVkIG5vZGVzXG4iLGNvdW50KTsKfQ==
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int iSSN;
char cName[30],cDept[10],cDesignation[30],cPhNo[11];
int iSalary;
struct node *plink;
struct node *nlink;
};
typedef struct node *NODEPTR;
NODEPTR fnGetNode(void);
void fnFreeNode(NODEPTR);
NODEPTR fnInsRear(NODEPTR);
NODEPTR fnDelFront(NODEPTR);
NODEPTR fnInsFront(NODEPTR);
NODEPTR fnDelRear(NODEPTR);
void fnDisplay(NODEPTR);
int main()
{
NODEPTR first=NULL;
int iChoice,iNum,i;
printf("\n Enter the number of Employees N:");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:\n",i+1);
first=fnInsRear(first);
}
for(;;)
{
printf("\n DLL OPERATIONS\n");
printf("=========");
printf("\n 1. Insert Rear \n 2. Delete Front\n 3. Insert Front \n 4. Delete Rear \n 5. Display \n 6. Exit \n");
printf("\n Enter your choice\n");
printf("\n Enter the number of Employees N:");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:scanf("%d",&iChoice);
switch(iChoice)
{
case 1:
first=fnInsRear(first);
break;
case 2:
first=fnDelFront(first);
break;
case 3:
first=fnInsFront(first);
break;
case 4:
first=fnDelRear(first);
break;
case 5:
fnDisplay(first);
break;
case 6:
exit(0);
}
}
return 0;
}
NODEPTR fnGetNode()
{
NODEPTR newborn;
newborn=(NODEPTR)malloc(sizeof(struct node));
if(newborn==NULL)
{
printf("n Memory overflow");
exit(0);
}
printf("\n Enter SSN:");
scanf("%d",&newborn->iSSN);
printf("\n Enter name:");
scanf("%s",newborn->cName);
printf("\n enter department:");
scanf("%s",newborn->cDept);
printf("\n Enter designation:");
scanf("%s",newborn->cDesignation);
printf("\n Enter salary:");
scanf("%d",&newborn->iSalary);
printf("\n Enter Phone No:");
scanf("%s",newborn->cPhNo);
return newborn;
}
void fnFreeNode(NODEPTR x)
{
free(x);
}
NODEPTR fnInsRear(NODEPTR firprintf("\n Enter SSN:");
scanf("%d",&newborn->iSSN);
printf("\n Enter name:");
scanf("%s",newborn->cName);
printf("\n enter department:");
scanf("%s",newborn->cDept);
printf("\n Enter designation:");
scanf("%s",newborn->cDesignation);
printf("\n Enter salary:");
scanf("%d",&newborn->iSalary);
printf("\n Enter Phone No:");
scanf("%s",newborn->cPhNo);st)
{
NODEPTR temp,cur;
temp=fnGetNode();
temp->plink=temp->nlink=NULL;
if(first==NULL)
return temp;
cur=first;
while(cur->nlink!=NULL)
{
cur=cur->nlink;
}
cur->nlink=temp;
temp->plink=cur;
return first;
}
NODEPTR fnInsFront(NODEPTR first)
{
NODEPTR temp;
temp=fnGetNode();
temp->plink=temp->nlink=NULL;
temp->nlink=first;
first=temp;
return first;
}
NODEPTR fnDelRear(NODEPTR first)
{
NODEPTR cur,prev;
if(first==NULL)
{
printf("\nDLL is empty\n");
return first;
}
cur=first;
if(cur->nlink==NULL)
{
printf("\n Node deleted for %s\n",cur->cName);
fnFreeNode(cur);
return NULL;
}
while(cur->nlink!=NULL)
{
cur=cur->nlink;
}
prev=cur->plink;
prev->nlink=NULL;
printf("\n Node deleted for %s\n",cur->cName);
fnFreeNode(cur);
return first;
}
NODEPTR fnDelFront(NODEPTR first)
{
NODEPTR temp;
if(first==NULL)
{
printf("\n DLL is empty\n");
return first;
}
if(first->nlink==NULL)
{
printf("\n Node deleted for %s\n", first->cName);
fnFreeNode(first);
return NULL;
}
temp=first;
first=first->nlink;
first->plink=NULL;
printf("\n Node deleted for %s\n",temp->cName);
fnFreeNode(temp);
return first;
}
void fnDisplay(NODEPTR first)
{
NODEPTR curr;
int count=0;
if(first==NULL)
{
printf("\n DLL is empty\n");
return;
}
printf("\n The contents of DLL are:\n");
currprintf("\n Enter the number of Employees N:");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
printf("\n Enter Data for node %d:=first;
printf("\n");
printf("\n SSN \t Name\tDept\tDesignation\tSalary\tPhone No");
while(curr!=NULL)
{
printf("\n%-5d\t%s\t%s\t%s\t%-7d\t%-11s",curr->iSSN,curr->cName,curr->cDept,curr->cDesignation,curr->iSalary,curr->cPhNo);
curr=curr->nlink;
count++;
}
printf("\n\nDLL has %d nodes\n",count);
}