#include<iostream>
using namespace std;
int findmaxindex(int a[],int ,int);
void swap(int a[],int ,int);
int main(){
int n;
cout<<"give the number of elements to sort"<<endl;
cin>>n;
if(n>100){cout<<"invalid"<<endl;
return -1;
}
if(n<=0){cout<<"invalid"<<endl;
return -1;
}
int count,a[100];
cout<<"give"<<n<<"integers to sort"<<endl;
for(count=0;count<n;count++){
cin>>a[count];
}
int currtop,currmaxindex;
for(currtop=0;currtop<n;currtop++){
currmaxindex=findmaxindex(a,currtop,n);
swap(a,currtop,currmaxindex);
}
return 0;
}
int findmaxindex(int a[],int start,int end){
int i,currmaxindex=start;
for(i=start;i<end;i++){
if(a[i]>=a[currmaxindex]){
currmaxindex=i;
}return currmaxindex;
}
}
void swap(int a[],int index1,int index2){
int temp;
temp=a[index1];
a[index1]=a[index2];
a[index2]=temp;
return ;
}
Satish_14 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
tinstaafl 1,176 Posting Maven
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
tinstaafl 1,176 Posting Maven
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
DGPickett 20 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.