several different pivots in quicksort

I have been working on this for the past little while and have come to a point where I am unsure how to fix. The program is supposed to take 3 separate files test_1.txt , test_2.txt , and inputarray.txt . I am supposed to run each set of data through three different quicksorts using different pivots. The first using the first number in the array, the second using the median of three pivot, and the final pivot is a random number from the set.
Here is the code that I have so far:
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
#include <ctime>
 
using namespace std;

int test_1[5];
int test_2[18];
int inputarray[100000];

void first_element_quicksort(int arr[], int start, int end)
{
	int i, j, x, temp;
	if(start < end)
	{
    	i = start;
    	x = arr[end];
    	
    	for(j = start; j < end; j++)
    	{
        	if(arr[j] <= x)
        	{
            	if(arr[j] < arr[i])
            	{
                temp = arr[j];
                arr[j] = arr[i];
                arr[i] = temp;
            	}
            i++;
        	}
    	}
	}
    else
    {
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    
    if(x != i)
    {
        temp = arr[end];
        arr[end] = arr[i];
        arr[i] = temp;
    }

    first_element_quicksort(arr, start, i - 1);
    first_element_quicksort(arr, i + 1, end);
}

int random_partition(int* arr, int start, int end)
{
    srand(time(NULL));
    int pivotIdx = start + rand() % (end-start+1);
    int pivot = arr[pivotIdx];
    swap(arr[pivotIdx], arr[end]); 
    pivotIdx = end;
    int i = start -1;

    for(int j=start; j<=end-1; j++)
    {
        if(arr[j] <= pivot)
        {
            i = i+1;
            swap(arr[i], arr[j]);
        }
    }
    swap(arr[i+1], arr[pivotIdx]);

    return i+1;
}

void random_quick_sort(int* arr, int start, int end)
{
    if(start < end)
	{
    int mid = random_partition(arr, start, end);
    random_quick_sort(arr, start, mid-1);
    random_quick_sort(arr, mid+1, end);
    }
}

void median_quicksort(int* arr, int start, int end)
{
    int q;
    int count = 0;
    count++;
    
    if (end-start<2) 
	return;
	
    q = median_partition(arr,start,end);
    median_quicksort(arr,start,q);
    median_quicksort(arr,q,end);
}
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
int median_partition(int* arr, int start, int end)
{
    int x=arr[start],y=arr[(end-start)/2+start],z=arr[end-1],i=start-1,j=end;
    if (y>x && y<z || y>z && y<x )
	x=y;
    else if (z>x && z<y || z>y && z<x ) 
	x=z;
    while (1) {
        do  {j--;count++;} while (arr[j] > x);
        do  {i++;count++;} while (arr[i] < x);
        if  (i < j) swap(&arr[i],&arr[j]);
        else return j+1;
    }                          
}

int main()
{
    ifstream fin1("test_1.txt", ios::binary);
    for (long i = 0; i < 5; i++)
    {
        fin1.read((char*)&test_1[i], sizeof(int));
    }
    
    ifstream fin2("test_2.txt", ios::binary);
    for (long j = 0; j < 18; j++)
    {
        fin2.read((char*)&test_2[j], sizeof(int));
    }
    
    ifstream fin3("InputArray.txt", ios::binary);
    for (long k = 0; k < 100000; k++)
    {
        fin3.read((char*)&inputarray[k], sizeof(int));
    }
    
    cout << "First number in array is the pivot.";
    cout << endl << "test_1.txt: ";
    first_element_quicksort(test_1, 0,5);
    cout << endl << "test_2.txt: ";
    first_element_quicksort(test_2, 0,18);
    cout << endl << "InputArray.txt: ";
	first_element_quicksort(inputarray, 0,100000);
    cout << endl << endl;
    
    cout << "Median of three random numbers in array is pivot.";
    cout << endl << "test_1.txt: ";
    median_quicksort(test_1, 0,5);
    cout << endl << "test_2.txt: ";
    median_quicksort(test_2, 0,18);    
    cout << endl << "InputArray.txt: ";
    median_quicksort(inputarray, 0,100000);    
    cout << endl << endl;
    
    cout << "Random number in array is pivot.";
    cout << endl << "test_1.txt: ";
    random_quick_sort(test_1, 0,5);
    cout << endl << "test_2.txt: ";
    random_quick_sort(test_2, 0,18);
    cout << endl << "InputArray.txt: ";
    random_quick_sort(inputarray, 0,100000);
    cout << endl << endl;
    
    fin1.close();
    fin2.colse();
    fin3.close();
    
    return 0;
}

sorry here is the rest of the code. Thank you for the help in advance.
Topic archived. No new replies allowed.