#include <iostream> #include <string> #include <windows.h> using namespace std; void swap(int* a, int* b) { int tmp = *a; *a = *b; *b = tmp; } int main() { int a[3] = { 7,2,5 }; if (*a > *(a + 1)) { swap(a, a + 1); } if (*(a + 2) < *(a + 1)) { swap(a + 1, a + 2); if (*(a + 1) < *a) { swap(a, a + 1); } } for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { cout << a[i] << " "; } cout << endl; system("pause"); return 0; }标签:顺序排列,tmp,int,由小到大,swap,数组,sizeof,include From: https://www.cnblogs.com/smartlearn/p/16769474.html