新年小玩一下# pets - 心有所宠
s*A
1 楼
用linked list实现stack, 这个pop函数 segmentation fault了
template T stack::pop(){
T d=head->data;
node *s=head;
head=head->next;
delete s;
ind--;
return d;
}
node和stack class的定义如下:
template struct node{
node *next;
T data;
node(node* n, T d):next(n),data(d){};
};
template class stack{
public: node *head;
int ind;
stack();
~stack();
void push(T d);
T pop();
bool isEmpty();
};
template
T d=head->data;
node
head=head->next;
delete s;
ind--;
return d;
}
node和stack class的定义如下:
template
node
T data;
node(node
};
template
public: node
int ind;
stack();
~stack();
void push(T d);
T pop();
bool isEmpty();
};