I created two projects. One in C ++ and one in Java. I checked the time for QuickSort and SelectionSort for both. Oddly enough, I found a very strange behavior.
Here are the results for an array of size 10,000:
SelectionSort Java: 80 ms
SelectionSort C ++: 2914 ms
QuickSort Java: 1 ms
QuickSort C ++: ~ 45 seconds
Now call me crazy, but I have always been taught that QuickSort is the fastest. This is confirmed in Java, but in C ++ it completely closes.
So my question is, does C ++ handle QuickSort differently?
I tried to support functions the same between languages, and they are exactly the same, except for using a vector in C ++ vs an int array. I would prefer to use a vector anyway, because the actual project that I want to use for sorting in C ++ requires a vector.
I am sure this is a dumb mistake or something that I am doing, but please provide some idea of why this is happening.
EDIT:
In my opinion, I see what the problem is. Thanks to everyone for the very quick answers. I will modify my code to work as intended. I knew this was a simple mistake. In addition, although the question asked is rather confusing, the answers are educational.
java c ++ quicksort compare
Timlankey
source share