Skip to content

Commit d8430f9

Browse files
committed
fixed selection sort
1 parent 5d1ff06 commit d8430f9

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

selection-sort.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
#include "sort.h"
1010
#include <iostream>
11-
11+
using namespace std;
1212
void
1313
SelectionSort::sort(int A[], int size) // main entry point
1414
{
15+
cout << "Selection Sort!" << endl;
1516
num_cmps = 0;
1617
int min = 0;
1718
int temp = 0;
18-
for(int n = 1; n < size; ++n)
19+
for(int n = 0; n < size; ++n)
1920
{
2021
num_cmps++;
21-
min = n-1;
22-
for(int j = n; j < size; ++n)
22+
min = n;
23+
for(int j = n + 1; j < size; ++j)
2324
{
2425
num_cmps++;
2526
if(A[j] < A[min])

selection-sort.o

472 Bytes
Binary file not shown.

sort

132 Bytes
Binary file not shown.

sort.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ int main(int argc, char** argv)
103103
}
104104

105105
/* read number of integers */
106+
cout << "Enter Size >>>";
106107
int size; //number of integers
107108
if (!(cin >> size)) return 1; //exit abnormally
108109

sort.o

100 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)