Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- //#include"queue.h"
- struct node{
- int data;
- struct node *next;
- };
- struct list{
- struct node *head;
- };
- struct node* createNode()
- {
- int a;
- struct node* x=malloc(sizeof(struct node));
- scanf("%d",&a);
- x->data=a;
- x->next=NULL;
- return x;
- }
- int enqueue(struct list* l,struct node* newnode)
- {
- struct node* x;
- if(l->head==NULL)
- {
- l->head=newnode;
- x=l->head;
- }
- else
- {
- x->next=newnode;
- x=x->next;
- }
- }
- void displayList(struct list* l)
- {
- struct node* x = l->head;
- while(x!=NULL)
- {
- printf("\n %d \n",x->data);
- x = x->next;
- }
- getch();
- }
- struct node* dequeue(struct list* l)
- {
- struct node* x;
- if(l->head==NULL)
- {
- return 0;
- }
- else
- {
- x=l->head;
- l->head=(l->head)->next;
- }
- return x;
- }
- int getChoice(int choice){
- char ch=10;
- while(ch!=13){
- system("cls");
- if(choice==1){
- printf("\n -->\tE N Q U E U E");
- }
- else printf("\n\tEnque");
- if(choice == 2)
- printf("\n -->\tD E Q U E U E");
- else printf("\n\tDeque");
- if(choice == 3)
- printf("\n -->\tD I S P L A Y");
- else printf("\n\tDisplay");
- if(choice == 4)
- printf("\n -->\tQ U I T");
- else printf("\n\tQuit");
- printf("\n\n[ Use UP and DOWN arrow to select an ooption ]");
- ch = getch();
- if(ch == 72)
- choice--;
- else if(ch == 80)
- choice++;
- if(choice<1)
- choice = 1;
- else if(choice>4)
- choice = 4;
- }
- return choice;
- }
- int main()
- {
- int choice=1;
- char ch;
- struct node* tempnode;
- struct list l;
- l.head = NULL;
- while(choice!=4){
- choice = getChoice(choice);
- switch(choice){
- case 1: tempnode = createNode();
- enqueue(&l,tempnode);
- printf("\n\n New node added SUCCESSFULLY.");
- displayList(&l);
- break;
- case 2: tempnode = dequeue(&l);
- if(tempnode!=NULL)
- printf("\n\n Node deleted SUCCESSFULLY\n Deleted value: %d",tempnode->data);
- displayList(&l);
- break;
- case 3: displayList(&l);
- break;
- case 4: printf("\n\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement