135-1821-9792

链表的遍历-逆向输出1

#include

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了梨林免费建站欢迎大家使用!

#include

#define N 9

typedef struct node{

       int  data;

       struct node * next;

}ElemSN;

ElemSN  * Createlink(int a[],int n){  

        int i;

        ElemSN * h=NULL,* tail, * p;

        for( i=0;i

                p=(ElemSN *)malloc(sizeof(ElemSN));

                p->data =a[i];

                p->next=NULL;

                if(!h)

                      h=tail=p;

                 else

                  tail=tail->next=p;

         }

         return h;

 }

    

PrePrintlink(ElemSN*h){

        ElemSN * Pend=NULL;

        ElemSN * p;

        while(Pend-h){                                  

              for(p=h;p->next-Pend;p=p->next );  

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

              Pend=p;                                            //pend为哨兵,标志的位置都为上次遍历停止的位置,停止就输出当前node的data

        }

}

 

int main(void){

    int a[N]={1,2,3,4,5,6,7,8,9};

    ElemSN * head;

    head=Createlink(a,9);

    PrePrintlink(head);

}


网页名称:链表的遍历-逆向输出1
当前路径:http://kswsj.com/article/pehgej.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号