如何使用优先级从左到右进行排序。优先级值为1-3。
#include <iostream>
Using namespace std;
Struct patient{
Char name[30];
Int priority;
}s[10;
在主要功能中,我使用for循环接收输入,我需要使用int优先级从左到右排列它们
原始问题是: 编写一个用于获取医院患者记录的c ++程序,并根据优先级NO安排患者,低优先级的患者应左对齐,高优先级的患者应右对齐。该程序应使用数组数据结构和选择对记录进行排序。
我真的很感谢您能提供帮助
答案 0 :(得分:0)
这是一种转换代码以执行排序的方法
#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>
)