week9 T8.c clang-format
This commit is contained in:
14
week9/T8.c
14
week9/T8.c
@@ -65,8 +65,10 @@ void QuickSort(int *A, int left, int right) {
|
|||||||
j = right - 1;
|
j = right - 1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (A[++i] < pivot) {}
|
while (A[++i] < pivot) {
|
||||||
while (A[--j] > pivot) {}
|
}
|
||||||
|
while (A[--j] > pivot) {
|
||||||
|
}
|
||||||
if (i >= j) {
|
if (i >= j) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -74,13 +76,13 @@ void QuickSort(int *A, int left, int right) {
|
|||||||
}
|
}
|
||||||
Swap(&A[i], &A[right - 1]);
|
Swap(&A[i], &A[right - 1]);
|
||||||
|
|
||||||
QuickSort(A, left, i -1);
|
QuickSort(A, left, i - 1);
|
||||||
QuickSort(A, i + 1, right);
|
QuickSort(A, i + 1, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Median3(int *A, int left, int right) {
|
int Median3(int *A, int left, int right) {
|
||||||
int center = (left + right) / 2;
|
int center = (left + right) / 2;
|
||||||
|
|
||||||
if (A[left] > A[center]) {
|
if (A[left] > A[center]) {
|
||||||
Swap(&A[left], &A[center]);
|
Swap(&A[left], &A[center]);
|
||||||
}
|
}
|
||||||
@@ -130,6 +132,6 @@ void Swap(int *a, int *b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintTimeDuration(clock_t start_time, clock_t end_time) {
|
void PrintTimeDuration(clock_t start_time, clock_t end_time) {
|
||||||
printf("Time cost: %ld ms\n", (end_time - start_time) / (CLOCKS_PER_SEC / 1000));
|
printf("Time cost: %ld ms\n",
|
||||||
|
(end_time - start_time) / (CLOCKS_PER_SEC / 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user