-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection.cpp
More file actions
49 lines (41 loc) · 836 Bytes
/
Selection.cpp
File metadata and controls
49 lines (41 loc) · 836 Bytes
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
#include<iostream>
using namespace std;
void swap(int *x, int *y)
{
int temp=*y;
*y=*x;
*x=temp;
}
void printArray(int arr[], int size)
{
for(int i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
}
void selectionSort(int arr[], int size)
{
int kindex=0;
for(int i=0; i<size-1;i++)
{
int k=arr[i];
for(int j=i+1;j<size;j++)
{
if(k>arr[j])
{
k=arr[j];
swap(&arr[i],&arr[j]);
}
}
}
cout<<endl<<"Array after sorting"<<endl;
printArray(arr,size);
}
int main()
{
int arr[]={90,60,6,5,100,70,80};
int size=(sizeof(arr)/sizeof(arr[0]));
cout<<"Array before Sorting"<<endl;
printArray(arr,size);
selectionSort(arr,size);
}