1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
class HeroNode { public int no; public String name; public String nickname; public HeroNode next; public HeroNode(int hNo,String hName,String hNickName) { this.no = hNo; this.name = hName; this.nickname = hNickName; } @Override public String toString() { return "HeroNode [no=" + no + ", name=" + name + ", nickname=" + nickname + "]"; } }
class SingleLinkedList1{ private static final HeroNode head = new HeroNode(0,"",""); public void add(HeroNode heroNode) { HeroNode temp = head; while(true) { if(temp.next == null) { break; } temp = temp.next; } temp.next = heroNode; } public void showList() { if(head.next == null) { System.out.println("链表为空"); return; } HeroNode temp = head.next; while(true) { if(temp == null) { break; } System.out.println(temp.toString()); temp = temp.next; } } }
|