首页 > 其他 > 详细

链表的创建,遍历,清除

时间:2014-09-25 22:50:28      阅读:323      评论:0      收藏:0      [点我收藏+]

node *creatline(int n)

{

    node *head=(node *)malloc(sizeof(node));

    head->data=rand()%100;

    head->next=NULL;

    node *p=head;

    int i=0;

    while (i<n-1) {

        p->next=(node *)malloc(sizeof(node));

        p->next->data=rand()%100;

        p->next->next=NULL;

        p=p->next;

        i++;

    }

    return head;

}

void printline(node *p)

{

    while (p!=NULL) {

        printf("%d\n",p->data);

        p=p->next;

    }

}

void releaseline(node *p)

{

    node *q=p->next;

    while (p!=NULL)

    {

        printf("%d\n",p->data);

        free(p);

        p=q;

        if (q!=NULL)

        {

            q=p->next;

        }

    }

    

}

void releaseline2(node *p)

{

    node *q=p->next;

    printf("%d\n",p->data);

    free(p);

    if (q!=NULL) {

        releaseline2(q);

    }

}

链表的创建,遍历,清除

原文:http://www.cnblogs.com/a514875560/p/3993713.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!