国内最大的教育考试网站之一
2008年11月软考程序员笔试考前全真模拟试题(40)
2008-11-6 15:42:27 来源:优易学(Qnr.Cn) 作者:Qnr.Cn

  距2008年11月全国计算机软件资格考试不远了。大家一起来交流一下吧!优易学网站整理了2008年11月全国计算机软件资格考试考前练习!优易学网站和各位一起学习!希望各位能够顺利通过2008年11月全国计算机软件资格考试!
  假设以带头结点的单循环链表作非递减有序线性表的存储结构。函数deleteklist(LinkList head)的功能是删除表中所有数值相同的多余元素,并释放结点空间。
  例如:链表初始元素为:
  (7,10,10,21,30,42,42,42,51,70)
  经算法操作后变为:
  (7,10,21,30,42,51,70)
  【函数1】
  void deleteklist(LinkList head)
  {
  LinkNode*p,*q;
  p=head->next;
  while(p!=head)
  {
  q=p->next;
  while( (1) )
  {
  (2) ;
  free(q);
  q=p->next;
  }
  p=p->next;
  }
  }

  【说明2】
  已知一棵完全二叉树存放于一个一维数组T[n]中,T[n]中存放的是各结点的值。下面的程序的功能是:从T[0]开始顺序读出各结点的值,建立该二叉树的二叉链表表示。
  【函数2】
  #include
  typedef struct node {
  int data;
  stuct node leftChild,rightchild;
  }BintreeNode;
  typedef BintreeNode*BinaryTree;
  void ConstrncTree(int T[],int n,int i,BintreeNode*&ptr)
  {
  if(i>=n) (3) ;∥置根指针为空
  else
  {
  ptr=-(BTNode*)malloc(sizeof(BTNode))
  ptr->data=T[i];
  ConstrucTree(T,n,2*i+1, (4) );
  ConstrucTree(T,n, (5) ,ptr->rightchild);
  }
  }
  main(void)
  {/*根据顺序存储结构建立二叉链表*/
  Binarytree bitree;int n;
  printf("please enter the number of node:\n%s";n);
  int*A=(int*)malloc(n*sizeof(int));
  for(int i=0;i<n;i++)scanf("%d,A+i);/*从键盘输入结点值*/
  for(int i=0;i<n;i++)printf("%d",A[i]);
  ConstructTree(A,n,0,bitree);
  }

  答案:
  (1)q!=head &&q->data==p->data
  (2)p->next=q->next
  (3)ptr=NULL
  (4)ptr->leftchild
  (5)2*i+2

【字体: 】【收藏本页】【打印本文】【告诉好友 】【投稿邮箱