我有一個列表,但現在我必須鏈接它。
這裏是我的程序(我刪除了函數內的代碼,使我的程序更容易閱讀)。指針的鏈接列表C++
#include <iostream>
using namespace std;
struct Student
{
char ime[16];
char priimek[16];
char vpisna[10];
char ocenaRV[10];
char ocenaDN[10];
char ocenaKV[10];
char ocenaVI[10];
Student *next;
};
void clean(Student* pointer,int x) // Delete random data
{
}
void dodajanje(int x,Student* s) // Add information about student
{
}
void brisi(Student* pointer,int x) // Delete information about student
{
}
int main()
{
int student,mesto, brisanje, ali = 0;
cout << "Number of students?." << endl;
cin >> student;
Student* s = new Student[student];
clean(s,student);
cout << endl;
cout << "Add student to i place in array." << endl;
cin >> mesto;
dodajanje(mesto, s);
for(int i=0;i<(student*2);i++)
{
cout << "add student = 1, delete student = 2, cout information = 3"<<endl;
cin>>ali;
if (ali == 1)
{
cout << endl;
cout << "Add student to i place in array." << endl;
cin >> mesto;
dodajanje(mesto, s);
}
else if (ali == 2)
{
cout << "delete student on i place ?" << endl;
cin >> brisanje;
brisi(s,brisanje);
}
else
{
break;
}
}
delete[] s;
return 0;
}
有人能解釋我如何將我的列表,因爲在我來到所有的教程代碼跨越是與此類似:
Node* temp = Node();
但是在我的程序我的代碼是:
Student* s = new Student[student];
現在我迷路了;
注:我必須創建動態鏈接列表。
非常感謝我會盡我所能 – yack