#include <stdio.h>
#include <malloc.h>
struct LNode{
int data;
struct LNode *next;
};
struct LNode *create(int n){
struct LNode *head,*p1,*p2;
int i,a;
head=NULL;
printf("input integers:\n");
for(i=n;i>0;i--){
p1=(struct LNode*)malloc(sizeof(struct LNode));
scanf("%d",&a);
p1->data=a;
if(head==NULL){
head=p1;
p2=p1;
}else{
p2->next=p1;
p2=p1;
}
}
p2->next=NULL;
return head;
}
struct LNode *reverse(struct LNode *head){
struct LNode *p,*r;
if(head->next&&head->next->next){
p=head;
r=p->next;
p->next=NULL;
while(r){
p=r;
r=r->next;
p->next=head;
head=p;
}
return he
c语言之单链表的创建和逆置
最新推荐文章于 2024-04-15 23:01:14 发布