问题描述
#include <iostream>
using namespace std;
struct node
{
int a;
node *next=NULL;
void insert()
{
cout<<"\n"<<"insert a value ";
cin>>a;
}
void show()
{
cout<<"value inserted is ";
cout<<a;
}
};
插入工作正常(addele func正常)
void addele(node *head)
{
node *curr = head;
node n;
while(!(curr->next==NULL))
{
curr=curr->next;
}
curr->next=&n;
n.insert();
n.show();
}
问题是,尽管我的代码适合显示功能,但运行代码后却得到了无限个零
void display(node *head)
{
node *curr = head;
while(!(curr->next==NULL))
{
cout<<curr->a;
curr=curr->next;
}
}
int main()
{
int ch;
node n,*h;
h=&n;
while (1)
{
cout<<" 1. Add Element \n";
cout<<" 2. display list \n";
cout<<" 3. Exit \n";
cin>>ch;
switch (ch)
{
case 1:addele(h);
break;
case 2:display(h);
break;
}
if (ch==3)
{
return 0;
}
}
return 0 ;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)