Practical No. 5 Objective - : Chandigarh University Data Structure Lab (Csp-209)
Practical No. 5 Objective - : Chandigarh University Data Structure Lab (Csp-209)
Practical No. 5 Objective - : Chandigarh University Data Structure Lab (Csp-209)
PRACTICAL NO. 5
OBJECTIVE
Write a C++ program to sort the given data using Selection Sort.
PROBLEM DEFINITION
The Selection sort algorithm is based on the idea of finding the minimum or maximum element
in an unsorted array and then putting it in its correct position in a sorted array.
ALGORITHM
BEGIN.
END.
FLOWCHART
CODE
#include<iostream>
int main()
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-1;i++)
min=a[i];
minIndex=i;
for(j=i+1;j<n;j++)
if(min>a[j])
min=a[j];
minIndex=j;
temp=a[i];
a[i]=a[minIndex];
a[minIndex]=temp;
for(i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
OUTPUT