Sorting Algorithms Optimizations from 2 loops to just 1 loop
Respostas da entrevista
Sigiloso
5 de out. de 2012
use quicksort. it has runtime of O(n.logn), or heapsort.
they both use one for loop and a heap/stack
1
Sigiloso
9 de abr. de 2012
#include
#include
using namespace std;
int main()
{
int list[10] = {5, 4, 3, 6, 7, 1, 2, 9, 8, 10};
for (int i=0; i= 0 && next list[next])
{
int temp = list[i];
list[i] = list[next];
list[next] = temp;
next--;
}
else next++;
}
}
for (int i=0; i<10; i++)
{
cout << list[i] << " ";
}
return 0;
}
Sigiloso
19 de abr. de 2012
you still have two loops
#include
#include
using namespace std;
int main()
{
int list[10] = {5, 4, 3, 6, 7, 1, 2, 9, 8, 10};
for (int i=0;j=i; i<10; i++;j++)
{
I can't remember, but you use two indices within one loop to sort using bubble sort
}
for (int i=0; i<10; i++)
{
cout << list[i] << " ";
}
return 0;
}