继上一小结 修改测试用例

这个template 还是有东西 的 可以自定义
- #ifndef SELECTIONSORT_STUDENT_H
- #define SELECTIONSORT_STUDENT_H
- //解决ide.h文件的多重引用的问题
- #include
- #include
- using namespace std;
-
- struct Student
- {
- /* data */
- string name;
- int score;
- //为了可以直接进行student的比较,这里需要运算符的重载
- bool operator<(const Student &otherStudent){
- return score != otherStudent.score ? score < otherStudent.score : name < otherStudent.name;
- }
- //为了打印输出结果,还需要对<<进行重载
- friend ostream& operator<<(ostream &os, const Student &student){
- os<<"Student: "<
" "< - return os;
- }
- };
-
-
-
-
- #endif //SELECTIONSORT_STUDENT_H
-
-
-
使用
- #include
- #include
- #include "Student.h"
- using namespace std;
-
- template<typename T >
-
- void selectionSort( T arr[], int n){
- for(int i = 0 ; i < n ; i++){
-
- //寻找【i,n之间的最小值】
- int minIndex = i;
- for( int j = i + 1 ; j < n ; j++)
- if(arr[j] < arr[minIndex] )
- minIndex = j;
-
- swap( arr[i] , arr[minIndex]);
-
- }
- }
-
-
- int main()
- {
- int a[5] = {5,62,3,58,44};
- selectionSort( a, 5 );
- for( int i = 0 ; i < 5 ; i++)
- cout<" ";
-
- cout<
-
- float b[4] = {4.4,2.3,5.63};
- selectionSort( b , 3);
- for( int i = 0 ; i < 3 ; i++)
- cout<" ";
- cout<
-
- string c[2] = {"z","b"};
- selectionSort( c , 2);
- for( int i = 0 ; i < 2 ; i++)
- cout<
" "; - cout<
-
- Student d[3] = {{"D",90} , {"C",89} , { "B", 114}};
- selectionSort( d , 3);
- for( int i = 0 ; i < 3 ; i++)
- cout<
- cout<
-
-
- return 0;
-
- }
-
-
-
相关阅读:
性能测试工具有哪些?原理是什么?怎么选择适合的工具?
java面试题整理《微服务篇》六
Python 数据可视化:Matplotlib库的使用
是谁制造了TikTok的商业化困境?
基于py的网络地址转换(NAT)
11. 盛最多水的容器
猿创征文 第二季| #「笔耕不辍」--生命不息,写作不止#
每日一练——Java
C指针 --- 初阶
开箱即用版本 满分室间质评之GATK Somatic SNV+Indel+CNV+SV
-
原文地址:https://blog.csdn.net/qq_68308828/article/details/133759858