Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<conio.h>
#include<iostream.h>

void sel_sort(int *,int);

int main(){
clrscr();
int *ar,n;
cout<<"Enter array size: ";
cin>>n;
ar=new int[n];
for(int i=0; i<n; i++){
cout<<"Element["<<i<<"]: ";
cin>>ar[i];
}
sel_sort(ar,n);
cout<<"\nSorted list:\n ";
for(i=0; i<n; i++)
cout<<ar[i]<<"\t";
getch();
return 0;
}

void sel_sort(int *a, int n){


int pos,tp,tpp;
for(int i=0; i<n; i++){
pos=i;
for(int j=i+1; j<n; j++){
if(a[pos]>a[j])
pos=j;
}
if(pos!=i){
tp=a[i];
a[i]=a[pos];
a[pos]=tp;
}
}
}

You might also like