使用选择排序对数组数据结构进行排序,但它不起作用

sorting a array data structure using selection sort, but it’s not working

本文关键字:排序 不起作用 数据结构 选择 数组      更新时间:2023-10-16

如何使用优先级从左到右进行排序。优先级值(如果为 1-3(。

#include <iostream>
Using namespace std;
Struct patient{
Char name[30];
Int priority;
}s[10;

在主函数中,我正在使用 for 循环进行输入,我需要使用 int 优先级从左到右顺序排列它们

最初的问题是: 编写一个 c++ 程序来获取医院的患者记录,并根据优先级 NO 排列患者,优先级低的患者应左对齐,高优先级的患者应向右对齐。该程序应使用数组数据结构和选择对记录进行排序。

我真的很感激有人可以帮忙

这是一种转换代码以执行排序的方法

#include <algorithm>
#include <functional>
#include <vector>
struct patient{
char name[30];
int priority;
bool operator>(const patient& rhs) const { return priority > rhs.priority; }
}s[10];
int main()
{
std::sort(s, s + 10, std::greater<patient>());

return 0;
}

如果要从最小到最大进行排序,请使用std::less而不是std::greater(您必须定义operator<而不是operator>(