程序如下: #include
using namespace std;template
class Node
{
public:
T data;
Node
Node()
{
next = NULL;
}
Node (T &x)
{
data = x;
next = NULL;
}
};template
class List
{
public:
List();
void create();
void reverse();
void print();private:
int count;
Node
};template
List
{
head = new Node
head->next = NULL;
count = 0;
}template
void List
{
T t;char ch = 'y';
Node
cout << "输入链表中的值:" << endl;
while (ch == 'y')
{
cin >> t;
p->next = new Node
p = p->next;
cout << "是否继续输(y/n)";
cin >> ch;
}
}template
void List
{
Node
while (p != NULL)
{
p->next = pre;
pre = p;
p = oldnext;
if (oldnext != NULL)
oldnext = oldnext->next;
}
head->next = pre;
}template
void List
{
Node
cout << "链表为:";
while (p != NULL)
{
cout << p->data << " ";
p = p->next;
}
cout << endl;
}void main()
{
List
l.create();
l.print();
l.reverse();
l.print();
}