Sort - might be wrong: the first element of the array is not taken into account)
vatavua opened this issue · 1 comments
vatavua commented
Are you sure the first argument of sort should be A+1? My opinion is that it should be A:
i.e.
std::sort(A,A+n+1);
kanubhav906 commented
The code is correct. Actually in the code we are ignoring the number present at zeroth(A[0]) index of the input array(Think of it as a dummy element) and starting our indexing from A[1] in order to apply the majority element finding algorithm,Same is for the case of sorting we are sorting only the elements starting from first index(A[1]) of the input array as we ignored A[0] index dummy element so we are applying the STL sort function with indexing (A+1,A+n+1).