#include<stdio.h>
#include<stdlib.h>
typedef struct LNode
{
int data;
struct LNode* next;
}LNode, * LinkList;
void CreateList_T(LinkList L, int n)
{
LinkList P, R;
R = L;
for (int i = 0; i <= n; i++)
{
P = (struct LNode*)malloc(sizeof(struct LNode));
P->data = i;
P->next = NULL;
R->next = P;
R = P;
}
}
void nizhiList(LinkList L)
{
printf("链表的逆置:\n");
LinkList p;
p = L;
LinkList q;
q = L;
LinkList t;
t = p;
while (q->next!=NULL){
q = q->next;
}
while (p->next != q){
t = p->next;
p->next = t->next;
t->next = q->next;
q->next = t;
}
}
void showList(LinkList L)
{
LinkList p;
p = L;
while (p->next!= NULL) {
p = p->next;
printf("%d\n", p->data);
}
}
int main()
{
LNode L;
CreateList_T(&L, 5);
showList(&L);
nizhiList(&L);
showList(&L);
return 0;
}
|