-
Here in the video we create a boolean function ‘compare’ which takes 2 strings to be compared as a parameter and while calling this function inside the sort function we do not pass the 2 strings. How does it know which two strings to compare?
-
What is the general syntax of the sort function? what parameters it intake?
String comparison
hey Varinda,
- yes you are not passing 2 strings but you are passing an array of string. The works of sort function is to just sort the this array depending upon your choice(ascending or decending). This sort function just take all pairs of string out of string array and sort them.
Which two string are compared that totally internal implementation of sort function and which not very much concerned for any programmer. Still if you want to know which 2 strings gets compared, write cout<<s1<<" and "<<s2<<endl; and you will get to know which two strings get comapred. - General Syntax of sort function which can be modified depending upon your choice(increasing or decreasing)
sort(startaddress, endaddress)
startaddress: the address of the first element of the array
endaddress: the address of the next contiguous location of the last element of the array.
So actually sort() sorts in the range of [startaddress,endaddress)
if you want to know more about sort function. Consider this link from C++ website
http://www.cplusplus.com/reference/algorithm/sort/
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.