#include
#include
using
template
struct
{
void
{
s1.push(t);
}
T
{
if(s2.empty())
{
if(s1.size()
throw;
while(!s1.empty())
{
s2.push(s1.top());
s1.pop();
}
}
return
}
void
{
if(s2.empty())
{
while(!s1.empty())
{
s2.push(s1.top());
s1.pop();
}
}
if(!s2.empty())
s2.pop();
}
stack<T>
stack<T>
};
int
{
MyQueue<int>
int
for(i=1;
{
mq.push(i);
}
for(i=1;
{
cout
mq.pop();
}
return
}
#include
#include
#include
#include
using
*****栈的存取规则是后进先出*****/
typedef
{
int
struct
}node;
typedef
{
node
}queue;
//初始化栈
queue
{
HQ->top
HQ->bottom
return
}
//入栈
queue
{
node
s
s->data
s->next
if(HQ->bottom
{
HQ->bottom
HQ->top
}
else
{
HQ->top->next
HQ->top
}
return
}
//出栈
int
{
node
int
if(HQ->bottom
printf("
else
{
b
p
x
if(HQ->bottom
{
HQ->top
HQ->bottom
}
else
{
while(b->next
{
b
}
HQ->top
HQ->top->next
free(p);
}
}
//printf("移除:%d\n",x);
return
}
queue
{
printf("入队:%d\n",x);
queue
hq
return
}
int
{
int
if(hq_b->bottom
{
while(hq_b->bottom
{
y
printf("出队:%d\n",y);
}
}
else
{
while(hq_a->bottom
{
temp
push(hq_b,
}
while(hq_b->bottom
{
y
printf("出队:%d\n",y);
}
}
return
}
int
{
queue
mystack_a
mystack_b
mystack_a
mystack_b
for(int
queue_in(mystack_a,
printf("\n");
for(int
queue_out(mystack_a,
return
}