#include<bits/stdc++.h>
using namespace std;
typedef struct Node
{
int data;
struct Node * next;
}*node;
struct Node* createlist()
{
struct Node*headNode = (struct Node*)malloc(sizeof(struct Node));
headNode->next = NULL;
headNode->data = NULL;
return headNode;
}
struct Node* createNode(int data)
{
struct Node*newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->next = NULL;
newNode->data = data;
return newNode;
}
void insertByTail(struct Node*headNode,int data)
{
struct Node*newNode = createNode(data);
struct Node*tailNode = headNode;
while(tailNode->next != NULL)
{
tailNode = tailNode->next;
}
tailNode->next = newNode;
}
void printList(node list)
{
node i = list->next;
for(;i != NULL; i = i->next)
{
printf("%d ", i->data);
}
puts("");
}
listReverse(node list)
{
node temp = list->next;
for(node i = temp->next; i != NULL; i = temp->next)
{
temp->next = i->next;
i->next = list->next;
list->next = i;
}
}
int main()
{
node list = createlist();
int i;
printf("输入链表的数据:\n");
while(cin >> i)
{
insertByTail(list, i);
if(cin.get() == '\n')
break;
}
listReverse(list);
printf("逆置后链表为:\n");
printList(list);
return 0;
}
balabalabalabalabalabalabalabalabalabalabalabalabalabala