-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTugasDasprogQuickshort.c
More file actions
63 lines (58 loc) · 1.21 KB
/
TugasDasprogQuickshort.c
File metadata and controls
63 lines (58 loc) · 1.21 KB
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
63
#include <stdio.h>
void Masukkan_Data(float X[], int Jumlah);
void Quick_Sort(float X[], int Atas, int Bawah);
void Tampilkan_Data(float X[], int Jumlah);
int main()
{
int N;
float Nilai[1000];
printf("Jumlah data ? ");
scanf("%d", &N);
printf("\n");
Masukkan_Data(Nilai, N);
Quick_Sort(Nilai, 0, N - 1);
printf("\n");
printf("Hasil setelah urut:\n");
Tampilkan_Data(Nilai, N);
return 0;
}
void Masukkan_Data(float X[], int Jumlah)
{
int I;
for (I = 0; I < Jumlah; I++)
{
printf("Data ke %d ? ", I + 1);
scanf("%f", &X[I]);
}
}
void Quick_Sort(float X[], int Bawah, int Atas)
{
int I, J, K;
float Sementara;
while (Atas > Bawah)
{
I = Bawah;
J = Atas;
Sementara = X[Bawah];
while (I < J)
{
while (X[J] > Sementara)
--J;
X[I] = X[J];
while (I < J && X[I] <= Sementara)
++I;
X[J] = X[I];
}
X[I] = Sementara;
Quick_Sort(X, Bawah, I - 1);
Bawah = I + 1;
}
}
void Tampilkan_Data(float X[], int Jumlah)
{
int I;
for (I = 0; I < Jumlah; I++)
{
printf("%f\n", X[I]);
}
}