码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 算法与数据结构 学习笔记2


    继上一小结 修改测试用例

    这个template 还是有东西 的 可以自定义

    1. #ifndef SELECTIONSORT_STUDENT_H
    2. #define SELECTIONSORT_STUDENT_H
    3. //解决ide.h文件的多重引用的问题
    4. #include
    5. #include
    6. using namespace std;
    7. struct Student
    8. {
    9. /* data */
    10. string name;
    11. int score;
    12. //为了可以直接进行student的比较,这里需要运算符的重载
    13. bool operator<(const Student &otherStudent){
    14. return score != otherStudent.score ? score < otherStudent.score : name < otherStudent.name;
    15. }
    16. //为了打印输出结果,还需要对<<进行重载
    17. friend ostream& operator<<(ostream &os, const Student &student){
    18. os<<"Student: "<" "<
    19. return os;
    20. }
    21. };
    22. #endif //SELECTIONSORT_STUDENT_H

    使用

    1. #include
    2. #include
    3. #include "Student.h"
    4. using namespace std;
    5. template<typename T >
    6. void selectionSort( T arr[], int n){
    7. for(int i = 0 ; i < n ; i++){
    8. //寻找【i,n之间的最小值】
    9. int minIndex = i;
    10. for( int j = i + 1 ; j < n ; j++)
    11. if(arr[j] < arr[minIndex] )
    12. minIndex = j;
    13. swap( arr[i] , arr[minIndex]);
    14. }
    15. }
    16. int main()
    17. {
    18. int a[5] = {5,62,3,58,44};
    19. selectionSort( a, 5 );
    20. for( int i = 0 ; i < 5 ; i++)
    21. cout<" ";
    22. cout<
    23. float b[4] = {4.4,2.3,5.63};
    24. selectionSort( b , 3);
    25. for( int i = 0 ; i < 3 ; i++)
    26. cout<" ";
    27. cout<
    28. string c[2] = {"z","b"};
    29. selectionSort( c , 2);
    30. for( int i = 0 ; i < 2 ; i++)
    31. cout<" ";
    32. cout<
    33. Student d[3] = {{"D",90} , {"C",89} , { "B", 114}};
    34. selectionSort( d , 3);
    35. for( int i = 0 ; i < 3 ; i++)
    36. cout<
    37. cout<
    38. return 0;
    39. }

  • 相关阅读:
    性能测试工具有哪些?原理是什么?怎么选择适合的工具?
    java面试题整理《微服务篇》六
    Python 数据可视化:Matplotlib库的使用
    是谁制造了TikTok的商业化困境?
    基于py的网络地址转换(NAT)
    11. 盛最多水的容器
    猿创征文 第二季| #「笔耕不辍」--生命不息,写作不止#
    每日一练——Java
    C指针 --- 初阶
    开箱即用版本 满分室间质评之GATK Somatic SNV+Indel+CNV+SV
  • 原文地址:https://blog.csdn.net/qq_68308828/article/details/133759858
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号