私は問題を理解するために多くの時間を費やしました.なぜそれが起こったのかわかりません.多分あなたたちは問題を見つけて理解することができます.私は必要なコメントを書きました.これが私のコードです:
#include <iostream>
struct node{
////I am creating node structure.
int number;
node *next;
node *previous;
};
struct list{
////I am creating list structure.It has head and tail pointers
node *head;
node *tail;
void add(node *); // Add function
void create(); // Create function
void deleteList(); // Delete function.
}emrah;
using namespace std;
int main(){
emrah.create(); // a list called 'emrah' has been created.
cout<<"Type 1."<<endl; // So that we lead user to add a node.
int selection;
cin>>selection;
if (selection==1){ // Suppose user typed 1.
node x;// new node is x.
emrah.add(&x); // x has been sent.
cout<<x.number; // Problem is here.On the command line,it shows like -9231
}
}
void list::create(){ // Create function.It has no problem.
head=NULL;
tail=NULL;
}
void list::add(node *Node){ // I think problem is around this function.
Node=new node;
cout<<"Sayi gir"<<endl;
cin>>Node->number;
cout<<Node->number;
head=tail=Node;
}
コマンドラインで入力したものとは異なる x の値を取得しています。見落としているポイントはどこですか? ありがとう。