0
我想创建一个C++基本链表应用程序,但我得到这个错误: C++ EXC_BAD_ACCESS链表
这里是我的节点类:
class node {
friend class graph;
int n;
node *next;
};
,这里是我的图类:
class graph{
private:
node *first;
node *last;
public:
void input();
void show();
graph();
};
graph::graph(){
first = NULL;
last = NULL;
}
我想创建自号节点用户插入
void graph::input(){
node *n1 = new node();
std::cout << "Please Enter Number \n";
std::cin >> n1->n;
n1->next = NULL;
if (first==NULL){
first = last = n1;
}
else{
last->next = n1;
last = n1;
}
}
最后我想显示数字,但我得到错误!
void graph::show(){
node *current = first;
do {
std::cout << "///////////////\n" << current->n;
current = current->next;
}while (current->next == NULL);
}
int main() {
graph g = *new graph();
g.input();
g.show();
}
请让我知道如何解决这个错误,为什么我得到这个错误?
感谢的只有一个元素你回答 – Hamid 2015-04-05 11:05:13