码迷,mamicode.com
首页 > 其他好文 > 详细

从头到尾反向输出带头结点的单链表的每个节点的值

时间:2015-04-18 11:22:17      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

#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);
}

 

从头到尾反向输出带头结点的单链表的每个节点的值

标签:

原文地址:http://www.cnblogs.com/919czzl/p/4436928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!