Rand() and Quicksort

I am trying to sort the following code using quicksort by low to high. With the output in a separate text file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int i;
int array[10];
int odd;
int Max;
int counter = 0;


int main()

{
cout << "The 10 random elements are: ";
cout << endl;

srand ( time(0) );

for (int j = 0; j < 99; j++)
{
    i = rand() % 100;
    if (i != i - 1)
    array[j] = i;

else
{
    i = rand() % 100;
    array[j] = i;
}


}

for (int k = 0; k < 10 ; k++)
{
    cout << array[k] << "\n";

}

cout << endl;


return 0;
}
Last edited on
I can't really tell what you are asking.

Do you want to know how to use the standard library to sort array, or do you want help implementing the quicksort algorithm?
I would like help implementing the quicksort. I'm not sure where it goes in my program or how to even begin implementation.
for this simple example, you would just code quicksort as a function, and call it from main with your random array.
implementation is covered to death on the web... and it is recursive, so hopefully you have at least a basic understanding of this concept.
Topic archived. No new replies allowed.