aaman_rahman's blog

By aaman_rahman, history, 8 days ago, In English,

In c++ we can use sort(a,a+n) stl function...And i felt it is faster than quick sort and merge sort algo(NOT AT ALL SURE).I even got tle in a problem using merge sort/quick sort by creating it in my code.But when i used sort(a,a+n,cmp) i got AC.So does that mean that stl sort is better than those and can I use stl sort in my programs in future if i become an developer.

 
 
 
 
  • Vote: I like it  
  • -11
  • Vote: I do not like it  

»
8 days ago, # |
  Vote: I like it +35 Vote: I do not like it

Yes, STL is faster, but practice makes perfect, so it's better to write your own code. I advice you do the following everytime...

void ordenamiento_gaucho()
{
    bool finito = true;

    do
    {
        finito = true;

        for(int i = 1; i < N; i++)
            if(A[i] > A[i+1])
                swap(A[i],A[i+1]), finito = false;
    }while(!finito);
}
»
8 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Always use sort(a, a + n). That`s all :)

»
8 days ago, # |
  Vote: I like it +4 Vote: I do not like it

Yes, STL is faster.

Since sort in STL isn't just simple quick sort or merge sort, it integrates various kinds of sort into one function and uses different methods according to different situations. So, it may be faster than your expectation. xD