当前所在位置:珠峰网资料 >> 计算机 >> 软件水平 >> 正文
2015年计算机软件水平程序员笔试考前练习精选(36)
发布时间:2012/11/4 15:32:46 来源:城市网学院 编辑:admin
   假设以带头结点的单循环链表作非递减有序线性表的存储结构。函数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
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved