使用选择排序对数组数据结构进行排序,但它不起作用
sorting a array data structure using selection sort, but it’s not working
如何使用优先级从左到右进行排序。优先级值(如果为 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>
(
相关文章:
- 尝试使用C++中的模板进行BST排序,但在使用随机字符串进行测试时不起作用
- 我的C++合并排序代码不起作用。我在这里错过了什么?
- 使用选择排序对数组数据结构进行排序,但它不起作用
- c++ 选择排序在特定情况下不起作用
- 排序不起作用 c++
- 在 C++ 中使用 10 个随机整数的数组进行气泡排序不起作用
- 插入排序不起作用
- 分而治之合并排序不起作用
- C 排序字符串的动态阵列 - 排序不起作用
- 为什么tha std :: list ::排序不起作用
- C++向量<Struct>排序不起作用
- 快速排序不起作用(分段错误)
- 使用qsort对字符串进行排序不起作用
- 自定义结构排序不起作用
- 为什么我的快速排序不起作用
- 简单std::排序不起作用
- 为什么泡沫排序不起作用
- std::矢量排序不起作用
- 对向量进行排序不起作用
- 为什么这个基数排序不起作用