我需要重寫方法從索引移除項中減去索引所有其餘的項目號碼和1.重寫方法從索引移除項目由1
包括上述條件中減去索引的所有餘下項目號碼,我需要重寫「getLot」,因此它不依賴索引號來查找很多。它應該只能根據批號找到批次。因此,如果第2號批號被移除,那麼第3號批號將從第2號索引移至第1號索引,仍然會被找到第3批次,而不是第2號碼。 (指數從0開始的BTW)
這裏是我的代碼:
public Lot getLot(int lotNumber)
{
if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {
// The number seems to be reasonable.
Lot selectedLot = lots.get(lotNumber - 1);
// Include a confidence check to be sure we have the
// right lot.
if(selectedLot.getNumber() != lotNumber) {
System.out.println("Internal error: Lot number " +
selectedLot.getNumber() +
" was returned instead of " +
lotNumber);
// Don't return an invalid lot.
selectedLot = null;
}
return selectedLot;
}
else {
System.out.println("Lot number: " + lotNumber +
" does not exist.");
return null;
}
}
謝謝。
我重新標記的問題,因爲這似乎不是有什麼用JavaScript。如果有人能想到一個更好的標籤使用... – apnorton 2013-03-05 03:19:15
爲什麼不使用鏈表 – Parth 2013-03-05 03:22:56