LinkedList i=a; //a contains the nodes which are adjacent to the last element of g
for(String i1: i)
{
if(g.contains(i1) || i1.equals("o"))
{ continue; }
g.addLast(i1);
func(g);
g.removeLast();
}
所以通過這個看起來好像步驟走如下:
1)檢查當前String的存在,或者如果它等於「O」
2A)如果是繼續
2b)否則將當前字符串放在列表的末尾。
3)重複步驟1> 2
4)刪除列表
的最後一個元素,如果我讓代碼儘可能簡單給出的步驟它看起來像這樣:
func(LinkedList ll)
{
Set set = new HashSet(ll); //removes all duplicates
if(set.contains("o") { set.remove("o") ;} //these are strings so that works
LinkedList newLL = new LinkedList(set); //order still retained
newLL.poll(); //remove last element
}
對於初學者來說,我可以做一些代碼,'而(g.isEmpty())'絕不會出現在所有的,因爲你添加的東西'g^'就在那個循環之前。目前還不清楚這裏所有的變量是什麼意思,我很確定你會在這裏用幾行代碼來切換變量。 – 2012-07-05 18:29:44
_program似乎不工作?你面臨的具體問題是什麼?錯誤?例外? – Asif 2012-07-05 18:31:10
@GrailsGuy它顯然不是家庭作業 – user1355603 2012-07-05 18:34:43