思路: 栈是先入后出,所以我们可以考虑把栈一的数据从栈顶把数据压到另一个缓冲栈栈里。然后缓冲栈依次出栈,就实现了先入先出的逻辑,然后再把数据压回去。
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int size=0;
typedef struct no
{
int data;
struct no *pnext; //构造链表
struct no *ppre;
}node;
typedef struct
{
node head; //构造链表头和链表尾
node tail;
}lht;
void link_show(const lht *p)
{
node *pn=(node*)p->head.pnext;
while(pn!=&p->tail)
{
printf("%d ",pn->data); //遍历显示链表
pn=pn->pnext;
}
printf("\n");
}
void link_init(lht *p)
{
p->head.pnext=&p->tail;
p->head.ppre=NULL;
p->tail.pnext=NULL; //初始化链表
p->tail.ppre=