分别就栈的顺序存储结构和链式存储结构实现栈的各种基本操作。用C++实现
链栈
#include
#include
#include
using namespace std;
struct BitNode
{
char bitdata[10];
struct BitNode *lchild,*rchild;
};
class Dui
{
public:
Dui();
void In(struct BitNode *p);
void Out();
~Dui();
struct Node
{
struct BitNode *p;
struct Node *next;
};
struct Node *front,*rear,*temp;
};
Dui::Dui()
{
front=rear=(struct Node *)malloc(sizeof(struct Node));
}
Dui::~Dui()
{
cout<<"调用了析构函数"<}
void Dui::In(struct BitNode *p)
{
rear->p=p;
rear->next=(struct Node *)malloc(sizeof(struct Node));
rear=rear->next;
}
void Dui::Out()
{
if(rear==front)
{
cout<<"No data"< }
else
{
temp=(struct Node *)malloc(sizeof(struct Node));
temp=front;
front=front->next;
free(temp);
}
}
找本c++数据结构习题集