Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Code sharing of C++ quick sorting algorithm

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "C++ Quick Sort Algorithm Code Sharing". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

#include #include #include #include struct example{ int id; std::string name;};template template bool intCheck(int a, int b){ return (a

< b);}bool stringCheck(std::string a, std::string b){ for(int i = 0; i < a.length(); i++) a[i] = tolower(a[i]); for(int i = 0; i < b.length(); i++) b[i] = tolower(b[i]); if(strcmp(a.c_str(), b.c_str()) >

= 0) return false; else return true;}bool exampleCheck(example a, example b){ if(strcmp(a.name.c_str(), b.name.c_str()) >= 0) return false; else return true;} int iArray[] = { 2, 1, 56, 213, 2, 32, 32216, 14 }; std::string sArray[] = { "Hello", "how are you? ", "elephant", "aaah! ", "zzzzz", "queen" }; example structArray[] = { {1, "Joe"}, {4, "Billy"}, {2, "Zander"}, {3, "Tom"} }; quickSort(iArray, 0, 7, intCheck); quickSort(sArray, 0, 5, stringCheck); quickSort(structArray, 0, 3, exampleCheck); std::cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report