C++ c++;单向链表,函数不';不要使用公共类变量
我在'head'、'tail'、'cur'等上得到一个错误。从第43行开始,没有在此范围内声明。代码如下:C++ c++;单向链表,函数不';不要使用公共类变量,c++,C++,我在'head'、'tail'、'cur'等上得到一个错误。从第43行开始,没有在此范围内声明。代码如下: #include<iostream> #include<stdlib.h> #include<string> using namespace std; struct studentas { int numeris; string vardas; char pazymys; studentas *next; }; cl
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
struct studentas
{
int numeris;
string vardas;
char pazymys;
studentas *next;
};
class list
{
private:
studentas *head, *tail;
public:
list()
{
head=NULL;
tail=NULL;
}
};
char random()
{
static char c = 'A' + rand()%6;
return c;
}
void kurti(int &n, string v[])
{
cout << "kiek noresite studentu?" << endl;
cin >> n;
for (int i=0; i<n; i++)
{
studentas *temp=new studentas;
temp->numeris=rand()%10;
temp->vardas=v[rand()%10];
temp->pazymys=random();
temp->next=NULL;
if (head==NULL)
{
head=temp;
tail=temp;
temp=NULL;
}
else
{
tail->next=temp;
tail=temp;
}
}
}
void rodyti(string v[])
{
studentas *temp=new studentas;
temp=head;
while (temp!=NULL)
{
cout << temp->numeris << endl;
cout << temp->vardas << endl;
cout << temp-> pazymys << endl;
temp=temp->next;
}
}
void ideti(int pos, int n, string v[])
{
studentas *pre=new studentas;
studentas *db=new studentas;
node *temp=new node;
db=head;
for (int i=1;i<pos;i++)
{
pre=db;
db=db->next;
}
temp->numeris=rand()%10;
temp->vardas=v[rand()%10];
temp->pazymys=random();
pre->next=temp;
temp->next=cur;
}
int main()
{
int n;
string v[] = {"Adyss","Benas","Vycka","Koste","Petras","Gytis","Audrius","Juste","Ema","Vaidis"};
kurti(n,v);
rodyti(v);
ideti(pos,n,v);
return 0;
}
#包括
#包括
#包括
使用名称空间std;
结构学生
{
整数;
弦瓦达斯;
炭酶;
学生*下一步;
};
班级名单
{
私人:
学生*头,*尾;
公众:
列表()
{
head=NULL;
tail=NULL;
}
};
char random()
{
静态字符c='A'+rand()%6;
返回c;
}
void kurti(int&n,字符串v[]
{
cout n;
对于(int i=0;inumeris=rand()%10;
temp->vardas=v[rand()%10];
temp->pazymys=random();
temp->next=NULL;
if(head==NULL)
{
压头=温度;
尾=温度;
温度=零;
}
其他的
{
尾部->下一步=温度;
尾=温度;
}
}
}
void rodyti(字符串v[]
{
学生*临时=新学生;
温度=水头;
while(temp!=NULL)
{
数值公式vardas=v[rand()%10];
temp->pazymys=random();
预->下一步=温度;
温度->下一步=当前;
}
int main()
{
int n;
字符串v[]={“Adyss”、“Benas”、“Vycka”、“Koste”、“Petras”、“Gytis”、“Audrius”、“Juste”、“Ema”、“Vaidis”};
库尔蒂(n,v);
罗迪提(v);
ideti(pos,n,v);
返回0;
}
我正在寻找一些关于在函数中使用类的帖子,但尝试了其中一些,仍然不起作用。欢迎使用堆栈溢出。请花时间阅读并参考“您可以在此处询问的内容和方式”中的材料。在节点处发现一个错误,我修复了它,并将其更改为我需要的内容(学生,而不是节点)只有类成员和
friend
s可以看到私有成员,并且必须在类的实例上调用成员。