Please also use comments so that it is easy to understand the code
I understood if length of string is greater I will place it later and smaller string before but what if two strings are of same size how to compare them lexographically
I want create a function which compares the strings lexographically which was said in the video
@AyushKumar9032 Lexicographical sorting is not only dependent on length. Lexicographical sorting means you have to sort in the same way as a dictionary order where first you compare the characters…if the characters are same in both string then only you check their lengths.
Say for example:
bat and batman
prefix bat is similar in both the strings but length of bat is less that length of batman so bat will come before batman in lexicographic order.
Say if two strings are:
abc and cde
Here once you check the first character a and c, you get to know a<c so abc will come before cde in lexicographic order. It is not dependent on length here.
If you pass strings in STL sort function, it will by default sort it in lexicographic order.
I want to solveas if as I am solving in an interview
Not through stl you can even also even share a link
Please provide a code that compares lexogrpahically not any stl function
@AyushKumar9032 https://www.geeksforgeeks.org/sorting-strings-using-bubble-sort-2/
Refer this… This is lexicographic sorting without using stl sort function. Bubble sort is used here.
You just need to compare both the strings as you compare integers and then swap accordingly.