-1
我已经编写了一个将节点推入堆栈的代码,并且我已经使用单独链接列表实现了它。但是每当我运行它时,它都会显示运行时错误。请帮助我。在C++中使用链接列表实现堆栈
#include <iostream>
#include <string>
using namespace std;
struct node{
int key;
node *next;
}*head=NULL;
void push(node *n){
n->next=head->next;
head->key=n->key;
head->next=n;
cout<<head->key<<" ";
}
int main(){
node *x;
cin>>x->key;
push(x);
return 0;
}
我使用C++ 4.9.2(GCC-4.9.2) 请帮我找出我错了
UB,X不指向任何东西。 – Borgleader