0
我正在研究一段C#代碼,它添加了存儲在單獨鏈接列表中的數字。我創建了一個包含11 11 8的緩衝單鏈表。最終的名單必須看起來像1 2 9。每個大於10的元素必須將餘數傳遞給下一個數字,並將%10的結果傳遞給將創建1 2的最終列表。 如何處理從每個數字開始的結轉從左到右?添加號碼時如何處理遺留物?
我已經創建了以下邏輯,但顯然我忽略了某些東西。
for (int i = 0; i < bufferList.Size(); i++)
{
int mostLeftValue = Convert.ToInt32(bufferList.GetValue(i));
if (mostLeftValue >=10 && i + 1 < bufferList.Size())
{
int nextLeftValue = Convert.ToInt32(bufferList.GetValue(i + 1))+1;
int modedNextValue = nextLeftValue % 10;
finalList.InsertAtTail(modedNextValue);
}
int moddedValue = mostLeftValue %10 ;
finalList.InsertAtFront(moddedValue);
你的邏輯工作,謝謝。 – user843681