sdut.acm2012级《程序设计基础Ⅱ)》_链表 数据结构实验之链表三:链表的逆置

来源:互联网 发布:战狼网络播放怎么赚钱 编辑:程序博客网 时间:2024/05/05 23:42

#include <stdio.h>#include <malloc.h>struct node{    int inum;    struct node *next;};struct node *create(){    struct node *head,*tail,*p;    head = (struct node*)malloc(sizeof(struct node));    head->next = NULL;    tail = head;    do    {        p = (struct node *)malloc(sizeof(struct node));        p->next = NULL;        scanf("%d",&p->inum);        tail->next = p;        tail = p;    }while(p->inum != (-1));    return (head);}void Reverse(struct node *head){    struct node *p,*q;    p = head->next;    head->next = NULL;    q = p->next;    while(p != NULL)    {        p->next = head->next;        head->next = p;        p = q;        if(q !=NULL)            q = q->next;    }}void print(struct node *head){    struct node *p;    p = head->next->next;    while(p != NULL)    {        printf("%d ",p->inum);        p = p->next;    }}int main(){    struct node *Head;    Head = create();    Reverse(Head);    print(Head);    return 0;}


原创粉丝点击