artais 2022-03-05 11:00 采纳率: 61.1%
浏览 121
已结题

数据结构与算法的问题,使用C语言,如何将其补充完整

[](

#include <stdlib.h>
#include <stdio.h>

//SwapInt,交换x和y指向的内存地址的值 
bool SwapInt(int* x, int* y);

//ThreeIntSort,输入的整数存放在x1,x2,x3指向的内存地址 
//输出:要求x1,x2,x3地址中存放的整数是按照从小到大的顺序排好的 
bool ThreeIntSort(int* x1, int* x2, int* x3);

//FourIntSort,输入的整数存放在x1,x2,x3,x4指向的内存地址 
//输出:要求x1,x2,x3,x4地址中存放的整数是按照从小到大的顺序排好的 
bool FourIntSort(int* x1, int* x2, int* x3, int* x4);

//ThreeIntSort,输入的整数存放在x1,x2,x3,x4,x5指向的内存地址 
//输出:要求x1,x2,x3,x4,x5地址中存放的整数是按照从小到大的顺序排好的 
bool FiveIntSort(int* x1, int* x2, int* x3, int* x4, int* x5);

int main()
{
    int a,b,c,d,e;
    
    //从命令行读入5个整数,放在a b c d e五个变量里
    //补充实现代码
     
    if( ThreeIntSort( /*补充实现代码*/))
        printf("\n 前三个整数排序结果:%d %d %d\n", a, b, c, d);
        
    if( FourIntSort(/*补充实现代码*/))    
        printf("\n 前四个整数排序结果:%d %d %d %d\n", a, b, c, d);
    
    if( FiveIntSort(/*补充实现代码*/))    
        printf("\n 前五个整数排序结果:%d %d %d %d %d\n", a, b, c, d, e);
        
    return 0;
)


```**_
bool ThreeIntSort(int* x1, int* x2, int* x3)
{
    //补充实现代码 
}
bool FourIntSort(int* x1, int* x2, int* x3, int* x4)
{
    //补充实现代码 
}
bool FiveIntSort(int* x1, int* x2, int* x3, int* x4, int* x5)
{
    //补充实现代码 
}

bool SwapInt(int* x, int* y)
{
    //补充实现代码 
}


```)
要求:
-1) 阅读 job1.cpp 代码,补充 job1.cpp 中缺少的代码实现程序目标
a) 补充读入 5 个整数的代码;
b) 补充三个排序函数的代码;
c) 补充 main 函数中调用三个排序函数的代码;
d) 补充 SwapInt 函数的代码;
2) 从命令行读入的 5 个整数存放在 5 个变量中,不能存放在数组中;
3) 在 ThreeIntSort、FourIntSort、FiveIntSort 的实现中,不能把数值放在数
组中进行排序,不能使用 C/C++标准库;
4) 不能使用全局变量;
5) SwapInt 函数可以实现后被三个排序函数使用,也可以不使用。
  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2022-03-05 11:30
    关注
    #include <stdlib.h>
    #include <stdio.h>
     
    //SwapInt,交换x和y指向的内存地址的值 
    bool SwapInt(int* x, int* y);
     
    //ThreeIntSort,输入的整数存放在x1,x2,x3指向的内存地址 
    //输出:要求x1,x2,x3地址中存放的整数是按照从小到大的顺序排好的 
    bool ThreeIntSort(int* x1, int* x2, int* x3);
     
    //FourIntSort,输入的整数存放在x1,x2,x3,x4指向的内存地址 
    //输出:要求x1,x2,x3,x4地址中存放的整数是按照从小到大的顺序排好的 
    bool FourIntSort(int* x1, int* x2, int* x3, int* x4);
     
    //ThreeIntSort,输入的整数存放在x1,x2,x3,x4,x5指向的内存地址 
    //输出:要求x1,x2,x3,x4,x5地址中存放的整数是按照从小到大的顺序排好的 
    bool FiveIntSort(int* x1, int* x2, int* x3, int* x4, int* x5);
     
    int main()
    {
        int a,b,c,d,e;
        
        //从命令行读入5个整数,放在a b c d e五个变量里
        scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
        //补充实现代码
         
        if( ThreeIntSort(&a,&b,&c))
            printf("\n 前三个整数排序结果:%d %d %d\n", a, b, c);
            
        if( FourIntSort(&a,&b,&c,&d))    
            printf("\n 前四个整数排序结果:%d %d %d %d\n", a, b, c, d);
        
        if( FiveIntSort(&a,&b,&c,&d,&e))    
            printf("\n 前五个整数排序结果:%d %d %d %d %d\n", a, b, c, d, e);
    
        return 0;
    }
     
    
    bool ThreeIntSort(int* x1, int* x2, int* x3)
    {
        if(*x1 > *x2)
            SwapInt(x1,x2);
        if(*x1 > *x3)
            SwapInt(x1,x3);
        if(*x2 > *x3)
            SwapInt(x2,x3);
        return true;
    }
    bool FourIntSort(int* x1, int* x2, int* x3, int* x4)
    {
        ThreeIntSort(x1,x2,x3);
        ThreeIntSort(x1,x2,x4);
        ThreeIntSort(x2,x3,x4);
        return true;
    }
    bool FiveIntSort(int* x1, int* x2, int* x3, int* x4, int* x5)
    {
        FourIntSort(x1,x2,x3,x4);
        FourIntSort(x1,x2,x3,x5);
        FourIntSort(x1,x2,x4,x5);
        FourIntSort(x1,x3,x4,x5);
        FourIntSort(x2,x3,x4,x5);
        return true; 
    }
     
    bool SwapInt(int* x, int* y)
    {
        int t;
        t = *x;
        *x = *y;
        *y = t;
        return true;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月13日
  • 已采纳回答 3月5日
  • 创建了问题 3月5日

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料