void swapArr(vector <int> & a, int currIndex, int count){ int tmp = a[currIndex]; //首先記下來這個位置上原本的值 if (count < a.size()){ swapArr(a, a[currIndex], count + 1); } a[tmp] = currIndex; } int main() { vector<int> a = {3,2,0,1}; int tmp = a[0]; swapArr(a, 0, 0); for (int i = 0; i < a.size(); ++i){ cout << a[i] << endl; } system("pause"); }