我想每次將數組中的一個元素向右移動,同時將原始元素按C#中的特定順序保留。移動數組中的單個元素
好了,所以我一直要求改寫代碼,我可以理解爲什麼那麼這裏我們去:
我可能有一些48390
//the ar elements have been commented out to show that we never know what ar contains but only the that I will always want to shift; ar[4]
int[] ar = new int[5];
//ar[0] = 4
//ar[1] = 8
//ar[2] = 3
//ar[3] = 9
//ar[4] = 0
while(ar != 04839)
{
Shift code
}
我可能輸入5個號碼48390,如果你發現它的數字相同但只有一位數字。我想要一個while循環來旋轉4 ar [1]來移位,直到數字形成04839
我希望這是有道理的。我發佈這個問題是因爲大多數頁面發佈有關移動的信息是基於將所有元素移到右側,而我只是真的想移動一個特定的元素。
感謝您的期待。
編輯:我應該更具體。如果你不知道每個數組元素可能是什麼?所以我不能依靠「0」作爲主播。因爲另一組數字可能包含另一個數字,例如「00238」。
我對你的榜樣困惑,你可以澄清的代碼? – Justin
希望這能解決問題嗎?謝謝。 – Marshal