题解 | #牛牛的排序# c++代码
牛牛的排序
https://www.nowcoder.com/practice/26a0c92e9266443887a3bf81aff8e188
#include <iostream> using namespace std; void swap(int& a, int& b) { int temp; temp = a; a = b; b = temp; } void sort(int* array, int n) { for(int i = 0;i < n-1;i++) { for (int j = 0;j < n-i-1;j++) { if (array[j] > array[j+1]) { swap(array[j], array[j+1]); } } } } int main() { int n; cin >> n; int arry[100]; for (int i = 0; i < n; i++) { cin >> arry[i]; } sort(arry,n); for (int i = 0; i < n; i++) { cout << arry[i] << " "; } return 0; }