Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct queue
- {
- int data;
- struct queue* next;
- } node;
- node* front = NULL;
- node* rear = NULL;
- void Enqueue(int x)
- {
- node* temp =
- (node*)malloc(sizeof(node));
- temp->data =x;
- temp->next = NULL;
- printf("%d is added to the Queue list\n\n",x);
- if(front == NULL && rear == NULL)
- {
- front = rear = temp;
- return;
- }
- rear->next = temp;
- rear = temp;
- }
- void Dequeue()
- {
- node* temp = front;
- if(front == NULL)
- {
- printf("Queue is Empty\n");
- return;
- }
- if(front == rear)
- {
- front = rear = NULL;
- }
- else
- {
- front = front->next;
- }
- free(temp);
- printf("Element is deleted from Queue\n");
- }
- void Print()
- {
- node* temp = front;
- while(temp != NULL)
- {
- printf("%d ",temp->data);
- temp = temp->next;
- }
- printf("\n");
- }
- int main()
- {
- printf("Enter 1 to enqueue\nEnter 2 to Dequeue\nEnter 3 to print\n");
- int a,b;
- scanf("%d",&a);
- switch(a)
- {
- case 1:
- printf("Enter value to add to the queue\n");
- scanf("%d",&b);
- Enqueue(b);
- main();
- case 2:
- Dequeue();
- main();
- case 3:
- Print();
- main();
- default:
- printf("Wrong Keyword!\n");
- main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement