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 40 41 42 43 44 45 46 47 48 49 50 51
| #include<stdio.h> #include<stdlib.h> #include"链栈.c" Linkstack *S1; void enQueue(Linkstack *s,int e) { push(s,e); } void deQueue(Linkstack *s,int *e) { int m; if(!Stackempty(S1)) { pop(S1,&m); *e=m; } else { while(!Stackempty(s)) { pop(s,&m); push(S1,m); } pop(S1,&m); *e=m; } } int main() { Linkstack*S; int x; S=Create(S); S1=Create(S1); enQueue(S,1); printf("1进队列\n"); enQueue(S,2); printf("2进队列\n"); deQueue(S,&x); printf("\n%d出队列\n\n",x); enQueue(S,3); printf("3进队列\n"); enQueue(S,4); printf("4进队列\n"); deQueue(S,&x); printf("\n%d出队列\n",x); deQueue(S,&x); printf("\n%d出队列\n",x); deQueue(S,&x); printf("\n%d出队列\n",x); return 0; }
|