Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- int head=0;
- int tail=0;
- int maxsize=6;
- int item;
- int queue[6];
- void enqueue()
- {
- if(head==(tail+1)%maxsize)
- {
- printf("queue is full");
- }
- else
- {
- scanf("%d",&item);
- queue[tail]=item;
- ///new thing is added
- tail=(tail+1)%maxsize;
- printf("the item that went into the queue=%d\n\n",item);
- }
- }
- void dequeue()
- {
- if(head==tail)
- {
- printf("queu is empty");
- }
- else
- {
- item=queue[head];
- ///add a new thing
- head=(head+1)%maxsize;
- printf("item that gets out of the queue=%d",item);
- }
- }
- void traverse()
- {
- int i;
- printf("the items of the queue are \n\n");
- for(i=head;i<=tail;i++)
- {
- item=queue[i];
- printf("%d\n\n",item);
- }
- }
- int main()
- {
- int i,n;
- do
- {
- printf("1-enqueue\n2-dequeue\n3-traverse\n4-exit\n\n");
- scanf("%d",&n);
- switch(n)
- {
- case 1:
- enqueue();
- break;
- case 2:
- dequeue();
- break;
- case 3:
- traverse();
- break;
- case 4:
- break;
- }}while(n!=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement