forked from rmkcodingclub/AmazonProblems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem29.c
62 lines (53 loc) · 1.27 KB
/
problem29.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*Solved by
R. Balaji, Dept of IT
*/
#include<stdio.h>
void quicksort(int array[], int a, int b)
{
int pivotIndex, temp, index1, index2;
if(a < b)
{
pivotIndex = a;
index1 = a;
index2 = b;
while(index1 < index2)
{
while(array[index1] <= array[pivotIndex] && index1 < b)
{
index1++;
}
while(array[index2]>array[pivotIndex])
{
index2--;
}
if(index1<index2)
{
temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
}
temp = array[pivotIndex];
array[pivotIndex] = array[index2];
array[index2] = temp;
quicksort(array, a, index2-1);
quicksort(array, index2+1, b);
}
}
int main()
{
int array[100],n,i;
printf("Enter the number of element you want to Sort : ");
scanf("%d",&n);
printf("Enter Elements in the list : ");
for(i = 0; i < n; i++)
{
scanf("%d",&array[i]);
}
quicksort(array,0,n-1);
printf("The Second largest element in Sorted elements: ");
/*for(i=0;i<n;i++)
printf(" %d",array[i]);*/
printf("%d",array[n-2]);
return 0;
}