Lexicographical sorting

how to lexicographically sort int and string ,can you plz make a compare function for this.

If you want the default ascending order sort.
You can do something like this
string name=“ahdhkjc”
sort(name.begin(),name.end())

For other sorting configurations, you can use your own custom comparator as desired.

actually if we want to sort let’s say 112,12 so we get the order 12 follwed by 112

how to make compare function for this

12,112 is in ascending order.
So by default it will be sorted in this order without using any compare function

bool compare(int a,int b)
{
return a>b;
}

int arr[3]={1,11,121}
sort(arr,arr+3)

In this way you can sort in descending order

but lexicographically 12 is greater than 112 and i want to know how to compare lexicographically and make its function

i m not asking for aceding or decending order of array

For such case convert the number to string or take input the number in a string variable
You can convert integer to a string by using inbuilt to_string function and then use the sort function. It will then sort it lexicographically

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.