之间这一块没掌握好,今天突然想起来,写了一点。
写得很乱,之后改。
#include <iostream>
using namespace std;
struct stu
{
struct stu* p;
int num;
};
class list
{
public:
struct stu a[10];
list()
{
int i;
for (i = 0; i < 10; i++)
{
a[i].p = NULL;
}
}
void add(int x)
{
int j = x % 10;
struct stu* q= a[j].p ;
if (q == NULL)
{
q = new struct stu;
q->num = x; q->p = NULL;
a[j].p = q;
cout << a[j].p->num << endl;
}
else
{
while (q->p != NULL) { q = q->p; }
struct stu* temp;
temp = new struct stu;
temp->num = x;
temp->p = NULL;
q->p=temp;
cout <<q->p << endl << temp->num;
delete temp;
}
}
};
int main()
{
class list xin;
xin.add(5); xin.add(25);
return 0;
}
主要是用了个结构体。
指针使用要注意。