#include<stdio.h>
typedef struct node{
int data;
struct node *next;
}node,*nodep;
nodep createNode(){
int i,j;
nodep t,q;
nodep head=(nodep) malloc(sizeof(node));
head->next=NULL;
printf("请输入节点,以0结束\n");
scanf("%d",&i);
while(i!=0){
t= (nodep) malloc(sizeof(node));
t->data=i;
t->next=head->next;
head->next=t;
scanf("%d",&i);
}
return head;
}
void printNode(nodep head){
nodep t=head->next;
while(t){
printf("%d\n",t->data);
t=t->next;
}
}
void reverseNode(nodep head){
nodep cur=head->next;
nodep reHead=NULL;
while(cur!=NULL){
nodep preCur=cur;
cur=cur->next;
preCur->next=reHead;
reHead=preCur;
}
head->next=reHead;
}
main(){
nodep head=createNode();
printNode(head);
reverseNode(head);
printNode(head);
}
c单链表逆置
最新推荐文章于 2024-09-15 17:28:08 发布