Skip to content

Commit

Permalink
Selection_Sort
Browse files Browse the repository at this point in the history
This program is about selection sort in cpp.
  • Loading branch information
Veeno-Rai committed Oct 14, 2022
1 parent 623a34e commit 7011853
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sorting/selection_sort/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ using namespace std;

void selectionSort(int arr[],int size)
{
// enter your code here
int i, j, min_idx;

// One by one move boundary of unsorted subarray
for (i = 0; i < size-1; i++)
{
// Find the minimum element in unsorted array
min_idx = i;
for (j = i+1; j < size; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
// Swap the found minimum element with the first element
if(min_idx!=i)
swap(arr[min_idx], arr[i]);
}
}


Expand Down

0 comments on commit 7011853

Please sign in to comment.