Doubly Linked List of Professor Data with the fields ID Name Branch Area of specialization using Stack and Queues

Doubly Linked List of Professor Data with the fields ID Name Branch Area of specialization using Stack and Queues and 3rd Sem Data Structure and Application lab 6th program.

Design, Develop and Implement a menu driven Program in C for the following operations Doubly Linked List (DLL) of Professor Data with the fields: ID, Name, Branch, Area of specialization
a. Create a DLL stack of N Professor’s Data.
b. Create a DLL queue of N Professor’s Data
Display the status of DLL and count the number of nodes in it.

/* Design, Develop and Implement a menu driven Program in C for the following operationson Doubly Linked List (DLL) of Professor Data with the fields: ID, Name, Branch, Area of specialization
a. Create a DLL stack of N Professor’s Data.
b. Create a DLL queue of N Professor’s Data
Display the status of DLL and count the number of nodes in it. */


#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void create();
void display();
void stack();
void queue();
void insert_front();
void insert_rear();
int count=0;
struct node{
    int idno;
    char name[20],branch[20],specilise[20];
    struct node *llink,*rlink;
};
struct node *first=NULL,*last=NULL,*temp;
int main()
{
    int ch,n,i,el;
    printf("Doubly linked list of professor data \n");
    printf("1.Using Stack \n 2. Using Queues \n");
    scanf("%d",&el);
    switch(el){
        case 1:stack();
        break;
        case 2:queue();
        break;
        default:printf("Invalid choice\n");
    }
}
void queue(){
    int ch,n,i;
    while(1)
    {
        printf("1.Create \n 2.Display \n 3.Exit\n");
        printf("Enter the choice \n");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:printf("Enter the Number of Employee\n");
            scanf("%d",&n);
            for(i=0;i<n;i++)
            insert_rear();
            break;
            case 2:display();
            break;
            case 3:exit(0);
            default:printf("Invalid choice\n");
        }
    }  
}
void stack(){
    int ch,n,i;
    while(1){
        printf("1.Create\n2.Display \n3.Exit\n");
        printf("Enter the choice\n");
        scanf("%d",&ch);
        switch(ch){
            case 1:printf("Enter the number of Employe \n");
            scanf("%d",&n);
            for(i=0;i<n;i++)
            insert_front();
            break;
            case 2:display();
            break;
            case 3:exit(0);
            default:printf("Invalid Choice\n");
            break;
        }
    }
}
void create(){
    int idno;
    char name[50],branch[20],specilise[20];
    temp=(struct node*)malloc(sizeof(struct node));
    temp->llink=temp->rlink=NULL;
    printf("Enter Id Number , Name,Branch,Specilization \n");
    scanf("%d%s%s%s",&idno,name,branch,specilise);
    temp->idno=idno;
    strcpy(temp->name,name);
    strcpy(temp->branch,branch);
    strcpy(temp->specilise,specilise);
    count++;
}
void insert_front(){
    if(first==NULL)
    {
        create();
        first=temp;
        last=temp;
    }else{
        create();
        temp->rlink=first;
        first->llink=temp;
        first=temp;
    }
}
void insert_rear(){
    if(first==NULL)
    {
        create();
        first=temp;
        last=temp;
    }else{
        create();
        last->rlink=temp;
        temp->llink=last;
        temp->rlink=NULL;
        last=temp;
    }
}
void display(){
    struct node *p;
    if(first==NULL)
    {
        printf("List is Empty\n");
        return;
    }
    p=first;
    printf("Contents of list\n");
    while(p!=NULL)
    {
        printf("ID number =%d\n Name =%s \nBranch=%s\n Specilization=%s\n",p->idno,p->name,p->branch,p->specilise);
        p=p->rlink;
    }
    printf("Total number of Employee %d\n",count);
}

Leave a Reply

Your email address will not be published. Required fields are marked *