artais 2022-03-05 11:00 采纳率: 63.2%
浏览 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日

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同