-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