-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30.c
50 lines (45 loc) · 979 Bytes
/
30.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
#include <stdio.h>
void bubbleSort(int *arr, int n)
{
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void Sorted(int *arr, int n)
{
int i = 0, j = n - 1;
while (i < j)
{
printf("%d ", arr[j--]);
if (i < j) {
printf("%d ", arr[i++]);
}
}
if (i == j)
{
printf("%d ", arr[i]);
}
printf("\n");
}
int main()
{
int arr[10];
printf("请输入10个整数:\n");
for (int i = 0; i < 10; i++)
{
scanf("%d", &arr[i]);
}
bubbleSort(arr, 10);
printf("按照最大、最小、次最大、次最小等的顺序排序后的结果为:\n");
Sorted(arr, 10);
return 0;
}