亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何實現插入的順序與顯示的順序一致

如何實現插入的順序與顯示的順序一致

car 2017-10-11 23:34:57
代碼運行總是顯示順序與插入順序相反public?class?BusLine?{ int?id; String?name; BusLine?next; public?BusLine(int?id,?String?name)?{ this.id?=?id; this.name?=?name; } public?void?displayBusLine()?{ System.out.println(id?+?"->"?+?name); } }public?class?BusLineList?{ private?BusLine?first; public?BusLineList()?{ first?=?null; } public?void?insertFirst(int?id,?String?name)?{ BusLine?newBusLine?=?new?BusLine(id,?name); newBusLine.next?=?first; first?=?newBusLine; } public?void?displayList()?{ BusLine?current?=?first; while?(current?!=?null)?{ current.displayBusLine(); current?=?current.next; } } public?BusLine?delete(String?name)?{ BusLine?current?=?first; BusLine?previous?=?first; if?(current?!=?null?&&?name?!=?null)?{ while?(current.next?!=?null?&&?!name.equals(current.name))?{ previous?=?current; current?=?current.next; } } if?(current?==?first) first?=?first.next; else?if?(previous?!=?null)?{ previous.next?=?current.next; } return?current; } public?BusLine?find(String?name)?{ BusLine?current?=?first; if?(current?!=?null?&&?name?!=?null)?{ while?(current.next?!=?null?&&?!name.equals(current.name))?{ current?=?current.next; } } return?current; } }public?class?BusLineApp?{ public?static?void?main(String[]?args)?{ BusLineList?busLineList?=?new?BusLineList(); int?i?=?0; busLineList.insertFirst(++i,?"市光路"); busLineList.insertFirst(++i,?"嫩江路"); busLineList.insertFirst(++i,?"翔殷路"); busLineList.insertFirst(++i,?"黃興公園"); busLineList.delete("翔殷路"); busLineList.displayList(); BusLine?currentBusLine?=?busLineList.find("黃興公園"); System.out.println(currentBusLine.id); System.out.println(currentBusLine.name); } }
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號