广东工业大学数据结构AnyView参考答案

广东工业大学数据结构AnyView参考答案

觉得还行,请点赞关注,您的点赞,我的动力!

1、第一章

  1. image-20210902201634767

    #include "allinclude.h"  //DO NOT edit this line
    void Descend(int &a, int &b, int &c)  // 通过交换,令 a >= b >= c
    {   // Add your code here
        if(a < b){
          swap(a, b);
        }
        if(a < c){
          swap(a,c);
        }
        if(b < c){
          swap(b,c);
        }
    }
    
    void swap(int a, int b){
      int c;
      c = a;
      a = b;
      b = a;
    }
    
  2. image-20210902201916117

    #include "allinclude.h"  //DO NOT edit this line
    float Polynomial(int n, int a[], float x0) 
    {   // Add your code here
      float result=0;
      for(int i = 0; i <= n; i++){
        result += a[i]*pow((x0),i);
      }
      return result;
    }
    
  3. 。。。

  4. image-20210902202052317

    #include "allinclude.h"  //DO NOT edit this line
    Status Series(int a[], int n) { 
        // Add your code here
        if(n == 0){
          return ERROR;
        }
        int result=1, res = 1;
        for(int k = 1; k <= n; k++){
          res = 1;
          for(int j = 1; j <= k; j++){
            res = res * j;
          }
          res = res*pow(2,k);
          if(res > MAXINT){
            return EOVERFLOW;
          }
          a[k-1] = res;
        }
        return OK;
    
    }
    
  5. image-20210905091522410
    #include "allinclude.h"
    void printName(stuType student[], int index[], int n)
    { 
      for(int i = 0; i < n; i++){
            printf("%s\n", student[index[i]].name);
      }
    }
    
  6. image-20210905091723185
    #include "allinclude.h"
    float highestScore(stuType *student[], int n)
    {  // Add your code here
        float max=0;
        for(int i = 0; i < n; i++){
          if(max < student[i]->score){
            max = student[i]->score;
          }
        }
        return max;
    }
    
  7. image-20210905091832784
    #include "allinclude.h"
    void printFirstName_HighestScore(stuType *student[], int n)
    {  // Add your code here
        stuType *studentMax=NULL;
        float scoreMax=0;
        for(int i = 0; i < n; i++){
          if(scoreMax < student[i]->score){
            studentMax = student[i];
            scoreMax = student[i]->score;
          }
        }
        for (int i = 0; i < 4; i++) {
          printf("%c", studentMax->name[i]);
        }
        printf("\n%.2f\n",  studentMax->score);
    }
    
  8. image-20210905092214101
    #include "allinclude.h"
    void printLastName_HighestScore(stuType *student[], int n)
    {  // Add your code here
        stuType *studentMax=NULL;
        float scoreMax=0;
        for(int i = 0; i < n; i++){
          if(scoreMax <= student[i]->score){
            studentMax = student[i];
            scoreMax = student[i]->score;
          }
        }
        for (int i = 0; i < 4; i++) {
          printf("%c", studentMax->name[i]);
        }
        printf("\n%.2f\n",  studentMax->score);
    }
    
  9. image-20210905092344369
    #include "allinclude.h"  //DO NOT edit this line
    void A() {
    	printf("X\n");
    }
    void B() {
    	printf("Y\n");
    }
    
    int main()
    {
    	void (*funcp)(); //定义函数指针
    
    	funcp = A;
    	(*funcp)(); // 实际上调用了A( );
    
    	funcp = B;
    	(*funcp)(); // 实际上调用了B( );
    
    	return 0;
    }
    
  10. image-20210905092428811
    #include "allinclude.h"  //DO NOT edit this line
    void hello() 
    { 
    	printf("Hello world!\n"); 
    }
    
    void runFun(void (*pFun)()) 
    {
    	pFun();  //函数指针;
    }
    
    
    int main()
    {
    	runFun(hello);  //hello是实际要调用的函数
    
    	return 0;
    }
    
  11. image-20210905092514568
    #include "allinclude.h"
    StrSequence* reverseStr(StrSequence* strSeq)
    /*返回一个结构体,该结构体将strSeq中的字符串逆序存放*/
    {  // Add your code here
        int length    = strSeq->length;
        ElemType *str = (ElemType*)malloc(length);
        for(int i = length-1; i >= 0; i--){
          str[length-1-i] = strSeq->elem[i];
        }
        
        StrSequence *res = (StrSequence*)malloc(sizeof(StrSequence));
        res->elem   = str;
        res->length = length;
        return res;
    }
    
  12. image-20210905092747752
    #include "allinclude.h"  //DO NOT edit this line
    Status CreateSequence(Sequence &S, int n, ElemType *a) { 
      if(n <= 0) return ERROR;
       S.length = n;
       S.elem = a;
       return OK;
    }
    
  13. image-20210905092937216
    #include "allinclude.h"  //DO NOT edit this line
    LinkList MakeNode(ElemType x) { 
        // Add your code here
        LNode *head=(LNode*)malloc(sizeof(LNode));
        head->data = x;
        head->next = NULL;
        return head;
    }
    
  14. image-20210905093041765
    #include "allinclude.h"  //DO NOT edit this line
    LinkList CreateLinkList(ElemType x, ElemType y) { 
        // Add your code here
    
        LNode *head,*p;
        head=(LNode*)malloc(sizeof(LNode));
        p=(LNode*)malloc(sizeof(LNode));
        if(head!=NULL){
            head->data=x;
            head->next=p;
            }
        if(p!=NULL){
            p->data=y;
            p->next=NULL;
            }
        return head; 
        return NULL; // This is a temporary code. Change it if necessary.
    }
    
  15. image-20210905093128791
    #include "allinclude.h"  //DO NOT edit this line
    LinkList CreateOrdLList(ElemType x, ElemType y) { 
        // Add your code here
        LNode *head, *p;
        head = (LNode*)malloc(sizeof(LNode));
        p    = (LNode*)malloc(sizeof(LNode));
        
        head->next = p;
        p->next = NULL;
        if(x < y){
          head->data = x;
          p->data = y;
        } else {
          head->data = y;
          p->data = x;
        }
        return head;
    }
    

izeof(LNode));

      head->next = p;
      p->next = NULL;
      if(x < y){
        head->data = x;
        p->data = y;
      } else {
        head->data = y;
        p->data = x;
      }
      return head;
  }
  ```
  • 26
    点赞
  • 90
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值