Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 数据结构:我得到了不想要的值_C++_Data Structures - Fatal编程技术网

C++ 数据结构:我得到了不想要的值

C++ 数据结构:我得到了不想要的值,c++,data-structures,C++,Data Structures,我花了很多时间来理解这个问题。我不知道为什么会发生。也许你们可以发现并理解这个问题。我写了必要的评论。下面是我的代码: #include <iostream> struct node{ ////I am creating node structure. int number; node *next; node *previous; }; st

我花了很多时间来理解这个问题。我不知道为什么会发生。也许你们可以发现并理解这个问题。我写了必要的评论。下面是我的代码:

        #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;
        }
#包括
结构节点{
////我正在创建节点结构。
整数;
节点*下一步;
节点*先前;
};
结构列表{
////我正在创建列表结构。它有头指针和尾指针
节点*头;
节点*尾部;
void add(node*);//add函数
void create();//创建函数
void deleteList();//删除函数。
}埃姆拉;
使用名称空间std;
int main(){
emrah.create();//已创建名为“emrah”的列表。

cout在add中,使用接收用户输入的新对象覆盖参数
节点
x
列表::add
中从未被触摸过