We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Sorting
- Big Sorting
- Discussions
Big Sorting
Big Sorting
+ 0 comments C++
bool myCmp(string s1, string s2) { return ((s1.size() == s2.size()) ? (s1 < s2) : (s1.size() < s2.size())); } vector<string> bigSorting(vector<string> unsorted) { sort(unsorted.begin(), unsorted.end(), myCmp); return unsorted; }
+ 0 comments Java 8:
class Result implements Comparator<String>{ public int compare(String str1, String str2){ return (str1.length()==str2.length()) ? str1.compareTo(str2) : str1.length()-str2.length(); } public static List<String> bigSorting(List<String> unsorted) { Collections.sort(unsorted, new Result()); return unsorted; } }
+ 0 comments Python:
def bigSorting(unsorted): unsorted.sort(key=lambda s: (len(s), s)) return(unsorted)
+ 0 comments Want to use something simalar in JS to improve search of this website , basically I want functionaly of alphabetically arrange blog posts , which is not available by default in the theme I want to use, but when run in JS it has a lot of errors. I am not a professional developer my self but trying to solve this porblem on my own and practicing. sorting by numbers is possible by using this
function bigSorting(unsorted) { return unsorted.sort((a, b) => (BigInt(a) > BigInt(b))? 0 : -1 ); } bigSorting(unsorted).forEach(i=>console.log(i));
+ 0 comments C# best solution 9/9
public static List<string> bigSorting(List<string> unsorted) { unsorted.Sort((a,b)=>{ if(a.Length!=b.Length) return a.Length-b.Length; int strLen = a.Length; for(int v = 0; v < strLen; v++){ if( a[v] == b[v] ) continue; if( a[v] > b[v] ) return 1; return -1; } return 0; }); return unsorted; }
Load more conversations
Sort 856 Discussions, By:
Please Login in order to post a comment