#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef struct Node
{
int data;
struct Node *next;
}LNode;
void Creat_LinkList(LNode **head,int n)
{
LNode *p;
int x;
(*head) = (LNode*)malloc(sizeof(LNode));
//(*head)->data = x;
(*head)->next = NULL;
while(n--)
{
scanf("%d",&x);
p = (LNode*)malloc(sizeof(LNode));
p->data = x;
p->next = (*head)->next;
(*head)->next = p;
}
}
void print(LNode *h)
{
LNode *p;
p=h->next;
while(p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
}
}
int main()
{
LNode *s;
int n;
scanf("%d",&n);
Creat_LinkList(&s,n);
print(s);
return 0;
}
单链表的就地逆置
最新推荐文章于 2023-06-27 11:58:15 发布