Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int head=-1, tail=-1, arr[100];
- void enqueue(int n)
- {
- if(tail>=100)
- {
- printf("It's overflown.\n");
- return;
- }
- else if(head==-1 && tail==-1)
- {
- head=0;
- arr[++tail]=n;
- return;
- }
- else
- arr[++tail]=n;
- }
- int dequeue()
- {
- if(head==-1)
- {
- printf("It's empty.\n");
- return -1;
- }
- else
- {
- int temp=arr[head];
- head++;
- if(head>tail)
- {
- head=-1;
- tail=-1;
- }
- return temp;
- }
- }
- int main()
- {
- int i,n,x,y,a,b,sum=0;
- scanf("%d", &n);
- for(i=0; i<n; i++)
- {
- scanf("%d", &x);
- enqueue(x);
- }
- scanf("%d", &y);
- for(i=0; i<y; i++)
- {
- a=dequeue();
- sum=sum+a;
- printf("%d ", a);
- }
- printf("sum: %d\n", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement