[求助]双链表,运行不出来
#include<iostream>using namespace std;
typedef int datatype;
class node
{
public:
datatype data;
node *front;
node *next;
};
class ddlinkstack
{
public:
node *top;
void inistack();
void push(datatype x);
void print();
};
void ddlinkstack::inistack()
{
node *p=new node;
top=p;
top->next=NULL;
top->front=NULL;
}
void ddlinkstack::push(datatype x)
{
if(top->next==NULL)
{
node *p=new node;
p->data=x;
p->front=top;
p->next=top->next;
p->next=p;
}
else
{
node *p=new node;
p->data=x;
p->front=top;
p->next=top->next;
top->next=p;
p->next->front=p;
}
}
void ddlinkstack::print()
{
node *p=top->next;
while(p->next!=NULL)
{
cout<<p->data;
p=p->next;
}
cout<<p->data<<endl;
}
int main(void)
{
ddlinkstack s;
s.inistack();
s.push(555);
s.print();
return 0;
}