Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next;
- } node;
- node* top=NULL,*head=NULL;
- void enqueue(int x)
- {
- node*N=(node*)malloc(sizeof(node));
- N->a=x;
- N->next=NULL;
- if(top==NULL)
- {
- top=N;
- head=N;
- }
- else
- {
- node *list=top;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=N;
- top=N;
- }
- }
- int dequeue()
- {
- int data=0;
- node *temp;
- temp = head;
- data = head->a;
- head = head->next;
- free(temp);
- return data;
- }
- int main()
- {
- int x,n,i,m,l;
- printf("ENTER QUEUE INPUT: ");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- scanf("%d",&x);
- enqueue(x);
- }
- printf("\n");
- for(i=0; i<n; i++)
- {
- x=dequeue();
- printf("QUEUE %d OUTPUT :",i+1);
- printf("%d ",x);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment