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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#define INFILE1 "NumFile100K.txt"
#define INFILE2 "NumFile25K.txt"
#define INFILE3 "NumFile500.txt"
#define INFILE4 "NumFile5K.txt"
#define ARRAY_SIZE1 100000
#define ARRAY_SIZE2 25000
#define ARRAY_SIZE3 500
#define ARRAY_SIZE4 5000
int* read(int , string, int* );
void BubbleSort(int*, int);
void SelectionSort(int*,int);
void InsertionSort(int*,int);
int main()
{
clock_t beginTime = 0;
clock_t endTime = 0;
clock_t elapsedTime = 0;
long secondsElapsed = 0;
long milsElapsed = 0;
// wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
cout<<" Populating Arrays... <500 elements> "<<endl;
cout<<" Sorting "<<endl;
int list500[500];
read(ARRAY_SIZE3,INFILE3 ,list500);
beginTime = clock();
BubbleSort(list500, ARRAY_SIZE3);
endTime = clock();
cout << " SUMMARY RESULTS" << endl;
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <BubbleSort> " <<setw(6)<< ": " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE3,INFILE3 ,list500);
beginTime = clock();
SelectionSort(list500, ARRAY_SIZE3);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Selection Sort >: " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE3,INFILE3 ,list500);
beginTime = clock();
InsertionSort(list500, ARRAY_SIZE3);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Insertion Sort >: " << elapsedTime<<" milliseconds"<<endl;
//wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
cout<<endl<<endl<<" Populating Arrays... <5000 elements> "<<endl;
cout<<" Sorting "<<endl;
int list5000[5000];
read(ARRAY_SIZE4,INFILE4 ,list5000);
beginTime = clock();
BubbleSort(list5000, ARRAY_SIZE4);
endTime = clock();
cout << " SUMMARY RESULTS" << endl;
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <BubbleSort> " <<setw(6)<< ": " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE4,INFILE4 ,list5000);
beginTime = clock();
SelectionSort(list5000, ARRAY_SIZE4);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Selection Sort >: " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE4,INFILE4 ,list5000);
beginTime = clock();
InsertionSort(list5000, ARRAY_SIZE4);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Insertion Sort >: " << elapsedTime<<" milliseconds"<<endl;
//wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
cout<<endl<<endl<<" Populating Arrays... <25000 elements> "<<endl;
cout<<" Sorting "<<endl;
int list25000[25000];
read(ARRAY_SIZE2,INFILE2 ,list25000);
beginTime = clock();
BubbleSort(list25000, ARRAY_SIZE2);
endTime = clock();
cout << " SUMMARY RESULTS" << endl;
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <BubbleSort> " <<setw(6)<< ": " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE2,INFILE2 ,list25000);
beginTime = clock();
SelectionSort(list25000, ARRAY_SIZE2);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Selection Sort >: " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE2,INFILE2 ,list25000);
beginTime = clock();
InsertionSort(list25000, ARRAY_SIZE2);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Insertion Sort >: " << elapsedTime<<" milliseconds"<<endl;
//wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
cout<<endl<<endl<<" Populating Arrays... <100000 elements> "<<endl;
cout<<" Sorting "<<endl;
int list100000[100000];
read(ARRAY_SIZE1,INFILE1 ,list100000);
beginTime = clock();
BubbleSort(list100000, ARRAY_SIZE1);
endTime = clock();
cout << " SUMMARY RESULTS" << endl;
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <BubbleSort> " <<setw(6)<< ": " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE1,INFILE1 ,list100000);
beginTime = clock();
SelectionSort(list100000, ARRAY_SIZE1);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Selection Sort >: " << elapsedTime<<" milliseconds"<<endl;
read(ARRAY_SIZE1,INFILE1 ,list100000);
beginTime = clock();
InsertionSort(list100000, ARRAY_SIZE1);
endTime = clock();
elapsedTime = endTime - beginTime;
cout << " Elapsed Time <Insertion Sort >: " << elapsedTime<<" milliseconds"<<endl;
return 0;
}
int* read(int size , string file, int*storageArray)
{
int i = 0;
for(i = 0; i < size; i++)
storageArray[i] = 0;
// open the file
ifstream inputHandle(file, ios::in);
// check if the file opened
if(inputHandle.is_open() == true) {
// if the file opened, read integers until EOF (end of file) is encountered
i = 0;
while( !inputHandle.eof() ) {
if(i < size) {
inputHandle >> storageArray[i];
i++;
}
else {
cout << "ERROR: There are too many items in the file. (ARRAY_SIZE = " << size << ")" << endl;
break;
}
}
inputHandle.close();
}
return storageArray;
}
|