#include<iostream>
#include<string>
using namespace std;
struct Data
{
const int key;
string data;
Data(int key, string name) :key(key), data(name) {}
};
class Node
{
public:
Node(int key, string data) :nodeData(key, data)
{
next = NULL;
}
Node(int key, string data, Node* next) :nodeData(key, data), next(next)
{
}
Data getNodedata()
{
return nodeData;
}
Node* getNext()
{
return next;
}
protected:
Data nodeData;
Node* next;
};
class List
{
public:
List()
{
headNode = NULL;
size = 0;
}
void insert(int key, string data)
{
headNode = new Node(key, data, headNode);
}
void printList()
{
Node* pmove = headNode;
while (pmove != NULL)
{
cout << pmove->getNodedata().key <<"\t"<<pmove->getNodedata().data<< endl;
pmove=pmove->getNext();
}
}
protected:
Node* headNode;
int size = 0;
};
int main()
{
List* plist = new List;
Data info[3]{ { 520,"初七" }, { 666,"888" }, { 111,"222" } };
for (int i = 0; i < 3; i++)
{
plist->insert(info[i].key,info[i].data);
}
plist->printList();
return 0;
}