-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex83.c
More file actions
47 lines (40 loc) · 803 Bytes
/
Copy pathex83.c
File metadata and controls
47 lines (40 loc) · 803 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
// sort array using recursion
int getmaxIndex(int a[] , int size);
void sort(int a[], int size);
#include <stdio.h>
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int size = 10;
int i;
sort(a, size);
for(int i=0; i<size; i++)
{
printf("%d\t",a[i]);
}
}
void sort(int a[], int size)
{
int maxIndex,t;;
if(size>1)
{
maxIndex = getmaxIndex(a, size);
t= a[size-1];
a[size-1] = a[maxIndex];
a[maxIndex] = t;
sort(a, size-1);
}
}
int getmaxIndex(int a[] , int size)
{
int max , maxindex;
max= a[0]; // initialize the maximum value with 0th value
maxindex = 0;
int i;
for(i=1; i<size; i++)
{
if (max > a[i])
maxindex= i; // to get the maximum value index in the array
}
return maxindex;
}