题解 | #牛牛的排序#
牛牛的排序
https://www.nowcoder.com/practice/26a0c92e9266443887a3bf81aff8e188
#include <stdio.h> int sort(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 tmp = *(arr + j); *(arr + j) = *(arr + j + 1); *(arr + j + 1) = tmp; } } } for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } return 0; } int main() { int n; scanf("%d", &n); int arr[n]; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } sort(arr, n); return 0; }