链表逆置

# include <stdio.h>
# include <malloc.h>
# include <string.h>
typedef struct node 
{
    struct node *next;
    int data;
}LINK;
int main()
{
    int i,j,n,leag=0;
    LINK *p,*q,*head;
    head=(LINK *)malloc(sizeof(LINK));
    head->next=NULL;
    do
    {
        p=(LINK *)malloc(sizeof(LINK));
        scanf("%d",&p->data);
        p->next=head->next;
        head->next=p;
    }while(p->data != -1);
    p=head->next;
    while(p)
    {
        if(leag)
                printf(" ");
        if(p->data != -1)
        {
            printf("%d",p->data);leag++;
        }
        p=p->next;
    }
    printf("\n");
    return 0;
} 

 

posted on 2013-09-25 18:12  随风浪子的博客  阅读(81)  评论(0编辑  收藏  举报

导航