#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

typedef struct LinkList
{
    int data;
    struct LinkList *next;
}NODE;

NODE* Create_List()
{
    int n;
    NODE *p,*r,*L=(NODE*)malloc(sizeof(NODE*));
    L->data=0;
    L->next=NULL;
    r=L;
    scanf("%d",&n);
    while(1)
    {
        if(n<0)
            break;
        p=(NODE*)malloc(sizeof(NODE*));
        p->data=n;

        p->next=r->next;
        r->next=p;
        r=p;
        scanf("%d",&n);
    }
    return L;
}

void Display_List(NODE *L)
{
    if(L->next!=NULL)
        Display_List(L->next);
    printf("%d ",L->data);
}

void Find_Node(NODE *L)
{
    int i,j=0;
    NODE *p=L;
    printf("请输入要查找节点的位置:");
    scanf("%d",&i);
    for(i,j;j<i;j++)
       p=p->next;

    printf("所查找节点的值为:%d\n",p->data);
}

void main ()
{
    NODE *head;
    head=Create_List();
    Find_Node(head);
    printf("链表倒序输出如下:\n");
    Display_List(head);
}

 

posted on 2015-04-18 10:25  文森博客  阅读(1717)  评论(0编辑  收藏  举报