Skip to content

Commit 20dbdac

Browse files
committed
Create problem29.c
1 parent cdae990 commit 20dbdac

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

problem29.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*Solved by
2+
R. Balaji
3+
*/
4+
5+
6+
#include<stdio.h>
7+
void quicksort(int array[], int a, int b)
8+
{
9+
int pivotIndex, temp, index1, index2;
10+
11+
if(a < b)
12+
{
13+
pivotIndex = a;
14+
index1 = a;
15+
index2 = b;
16+
while(index1 < index2)
17+
{
18+
while(array[index1] <= array[pivotIndex] && index1 < b)
19+
{
20+
index1++;
21+
}
22+
while(array[index2]>array[pivotIndex])
23+
{
24+
index2--;
25+
}
26+
27+
if(index1<index2)
28+
{
29+
temp = array[index1];
30+
array[index1] = array[index2];
31+
array[index2] = temp;
32+
}
33+
}
34+
35+
temp = array[pivotIndex];
36+
array[pivotIndex] = array[index2];
37+
array[index2] = temp;
38+
39+
quicksort(array, a, index2-1);
40+
quicksort(array, index2+1, b);
41+
}
42+
}
43+
44+
int main()
45+
{
46+
47+
int array[100],n,i;
48+
printf("Enter the number of element you want to Sort : ");
49+
scanf("%d",&n);
50+
printf("Enter Elements in the list : ");
51+
for(i = 0; i < n; i++)
52+
{
53+
scanf("%d",&array[i]);
54+
}
55+
quicksort(array,0,n-1);
56+
printf("The Second largest element in Sorted elements: ");
57+
/*for(i=0;i<n;i++)
58+
printf(" %d",array[i]);*/
59+
printf("%d",array[n-2]);
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)