-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy path7-stackQueue.c
More file actions
40 lines (39 loc) · 774 Bytes
/
7-stackQueue.c
File metadata and controls
40 lines (39 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#define MAX 10001
int stack1[MAX];
int stack2[MAX];
int main()
{
char operate[5];
int top1=0,top2=0,i=0,n=0;
int num;
//for(;i<40;i++)
// printf("%d\t",stack1[i]);
scanf("%d",&n);
while(i<n)
{
scanf("%s",operate);
if(strcmp(operate,"PUSH")==0)
{
scanf("%d",&num);
stack1[top1++]=num;
}
else
{
if(top2==0)
{
while(top1)
stack2[top2++]=stack1[--top1];
}
if (top2)
printf("%d\n",stack2[--top2]);
else
printf("-1\n");
}
i++;
}
return 0;
}