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

数据结构与算法的问题,使用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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
  • 有问必答小助手 2022-03-05 13:05
    关注
    您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
    PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632
    评论
查看更多回答(1条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 求苹果推信imessage批量推信技术
  • ¥15 ubuntu 22.04 系统盘空间不足。隐藏的docker空间占用?(相关搜索:移动硬盘|管理系统)
  • ¥15 利用加权最小二乘法求亚马逊各类商品的价格指标?怎么求?
  • ¥15 c++ word自动化,为什么可用接口是空的?
  • ¥15 Matlab计算100000*100000的矩阵运算问题:
  • ¥50 VB6.0如何识别粘连的不规则的数字图片验证码
  • ¥16 需要完整的这份订单所有的代码,可以加钱
  • ¥15 Stata数据分析请教
  • ¥15 请教如何为VS2022搭建 Debug|win32的openCV环境?
  • ¥15 关于#c++#的问题:c++如何使用websocketpp实现websocket接口调用,求示例代码和相关资料