Code sharing of C++ quick sorting algorithm
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