C++编程问题 高手速度来解决啦

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:33:16
#include<iostream.h>
struct node
{
char name;
int price;
int grade;
int huogui;
int surplus;
node * next;
}use1;
class good
{
public:
node * addname();
private:
node * lian;
};
node * good::addname()
{
char name;int grade;int huogui;int surplus;int price;
node * lh=NULL, * temp;
cout<<"请想输入此商品的名字:"<<endl;
cin>>name;
cout<<"请输入此商品的价格:"<<endl;
cin>>price;
cout<<"请输入此商品的等级:"<<endl;
cin>>grade;
cout<<"请输入此商品的将要存放的货柜号:"<<endl;
cin>>huogui;
cout<<"请输入此商品的现在的库存量:"<<endl;
cin>>surplus;
lh=new node;//为新结点分配动态内存
if(lh==NULL) //内存分配不成功
{
cout<<"没有内存了,请关掉一些无用程序再打开不软件";
return NULL;
}
else
{
lh->name=n

for(int i=0;i<=n;i++)//写错 for(int i=1;i<=n;i++)

temp->next=NULL; //此处有问题
lh->next=temp; //可改为temp->next=lh; lh->temp 倒插

这个程序似乎超占内存!

temp->next=NULL;
lh->next=temp;
这个地方链表建立错误, lh始终没变,这样循环下来,只留下lh和最后一个temp了

我没有学过这个,但是我学过.net

请说清楚出现哪种效果。。。。。?