#include<stdio.h>
void swap (int arr[], int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
void ssort_down(int arr[], int n)
{
int temp;
for(int i=n-1; i>0; i--){
int largest =i;
for(int j=i-1; j>=0; j--){
if(arr[j] > arr[largest]){
largest =j;
}
}
temp = arr[i];
arr[i]=arr[largest];
arr[largest]=temp;
}
}
int max(int arr[], int start, int end)
{
int largest;
if(start == end){
return end;
}
largest = max(arr, start+1, end);
if(arr[start] > arr[largest]){
largest = start;
}
return largest;
}
void rec_ssort(int arr[], int n)
{
if(n==0){
return;
}
int biggest = max(arr, 0, n-1);
swap(arr,n-1, biggest);
rec_ssort(arr, n-1);
}
int main (void)
{
int arr[6] = {3,11,2,8,9,10};
ssort_down(arr, 6);
// for(int i=0; i<6; i++){
// printf("%d", arr[i]);
// }
printf("%d", largest);
return 0;
}
No comments:
Post a Comment