2009年9月全国计算机等级考试二级C语言程序设计题(73)
来源:优易学  2011-7-30 16:52:54   【优易学:中国教育考试门户网】   资料下载   IT书店
题目:反向输出一个链表。
  1.程序分析:
  2.程序源代码:
  /*reverse output a list*/
  #include "stdlib.h"
  #include "stdio.h"
  struct list
  { int data;
  struct list *next;
  };
  typedef struct list node;
  typedef node *link;
  void main()
  { link ptr,head,tail;
  int num,i;
  tail=(link)malloc(sizeof(node));
  tail->next=NULL;
  ptr=tail;
  printf("\nplease input 5 data==>\n");
  for(i=0;i<=4;i++)
  {
  scanf("%d",&num);
  ptr->data=num;
  head=(link)malloc(sizeof(node));
  head->next=ptr;
  ptr=head;
  }
  ptr=ptr->next;
  while(ptr!=NULL)
  { printf("The value is ==>%d\n",ptr->data);
  ptr=ptr->next;
  }}

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训