# Define stacksize 10
# Include "stdio. h"
# Include <malloc. h>
Typedef struct
{Int num [stacksize];
Int top;
} Seqstack;/* stack definition */
Typedef struct node
{Unsigned num;
Struct node * next;
} Linkqnode;
Typedef struct
{Linkqnode * front, * rear;} linkqueue;/* chain queue definition */
Void initstack (seqstack * s)/* initialize stack */
{S-> top =-1 ;}
Int push (seqstack * s, int e)/* inbound stack */
{If (s-> top = stacksize-1) {printf ("Stack is full! N "); return 0 ;}
S-> top ++;
S-> num [s-> top] = e; return 1;
}
Int pop (seqstack * s, int * e)/* output stack */
{If (s-> top =-1) return 0;
* E = s-> num [s-> top];
S-> top --;
Return 1;
}
Void printstack (seqstack * s)/* elements in the output stack, bottom of stack to top of stack */
{Int I;
For (I = 0; I <= s-> top; I ++)
Printf ("% 5d", s-> num [I]);
Printf ("n ");
}
Int initqueue (linkqueue * q)/* initialize queue */
{
Q-> front = (linkqnode *) malloc (sizeof (linkqnode ));
If (q-> front! = NULL)
{Q-> front-> next = NULL;
Q-> rear = q-> front; return 1;
}
Else return 0;
}
Int enterqueue (linkqueue * q, int e)/* queue */
{Linkqnode * s;
S = (linkqnode *) malloc (sizeof (linkqnode ));
If (s! = NULL)
{S-> num = e; q-> rear-> next = s; s-> next = NULL; q-> rear = s; return 1 ;}
Else return 0;
}
Int delqueue (linkqueue * q, int * e)/* team out */
{Linkqnode * p;
If (q-> front = q-> rear) return 0;
P = q-> front-> next;
Q-> front-> next = p-> next;
If (q-> rear = p) q-> rear = q-> front;
* E = p-> num;
Free (p); return 1;
}
Main ()/* main function */
{Seqstack s;
Linkqueue q;
Int goodsnum;
Initstack (& s );
Initqueue (& q );
Printf ("Enter the incoming product number,-1 end :");
Scanf ("% d", & goodsnum );
While (goodsnum! =-1)
{Push (& s, goodsnum); scanf ("% d", & goodsnum );}
Printf ("n original shelf: n ");
Printstack (& s );
While (s. top! =-1)
If (pop (& s, & goodsnum) enterqueue (& q, goodsnum );
While (q. front)-> next! = NULL)
{Delqueue (& q,
<