题解 | #牛牛的排序#
牛牛的排序
https://www.nowcoder.com/practice/26a0c92e9266443887a3bf81aff8e188
#include <stdio.h> #include<malloc.h> void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } int main() { int a; scanf("%d", &a); int* arr = malloc(sizeof(int) * a); for (int i = 0; i < a; i++) { scanf("%d", &arr[i]); } //冒泡排序 for (int i = 0; i < a - 1; i++) for (int j = i + 1; j < a; j++) { if (arr[i] > arr[j]) { swap(&arr[i], &arr[j]); } } for (int i = 0; i < a; i++)printf("%d ", arr[i]); return 0; }#C##排序算法#
0基础学C 文章被收录于专栏
0基础学C,从算法开始