题解 | #牛牛的排序#
牛牛的排序
https://www.nowcoder.com/practice/26a0c92e9266443887a3bf81aff8e188
#include <iostream> using namespace std; void sort(int *array, int n) { for (int *i = array; i != array + n - 1; ++i) { for (int *j = i + 1; j != array + n; ++j) { if (*i > *j) { int temp = *i; *i = *j; *j = temp; } } } } int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, n); for (int i = 0; i < n; ++i) cout << a[i] << " "; } // 64 位输出请用 printf("%lld")
简单地写个选择排序
C++题解 文章被收录于专栏
记录在牛客网用C++刷题的题解思路