c单链表逆置

来源:互联网 发布:mariadb mysql 对比 编辑:程序博客网 时间:2024/06/16 01:09
#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);}


                                             
0 0
原创粉丝点击