[C] 反向输出一个链表 →→→→→进入此内容的聊天室

来自 , 2020-04-13, 写在 C, 查看 109 次.
URL http://www.code666.cn/view/86e78499
  1. #include "stdio.h"
  2. /*reverse output a list*/
  3. #include "stdlib.h"
  4. #include "stdio.h"
  5. struct list
  6. {
  7.         int data;
  8.         struct list *next;
  9. };
  10. typedef struct list node;
  11. typedef node *link;
  12. void main()
  13. {
  14.         link ptr,head,tail;
  15.         int num,i;
  16.         tail= ( link ) malloc ( sizeof ( node ) );
  17.         tail->next=NULL;
  18.         ptr=tail;
  19.         printf ( "\nplease input 5 data==>\n" );
  20.         for ( i=0; i<=4; i++ )
  21.         {
  22.                 scanf ( "%d",&num );
  23.                 ptr->data=num;
  24.                 head= ( link ) malloc ( sizeof ( node ) );
  25.                 head->next=ptr;
  26.                 ptr=head;
  27.         }
  28.         ptr=ptr->next;
  29.         while ( ptr!=NULL )
  30.         {
  31.                 printf ( "The value is ==>%d\n",ptr->data );
  32.                 ptr=ptr->next;
  33.         }
  34. }
  35.  

回复 "反向输出一个链表"

这儿你可以回复上面这条便签

captcha