第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Java 自己寫了個(gè)鏈表類 為什么不能運(yùn)行 大神幫忙看下

Java 自己寫了個(gè)鏈表類 為什么不能運(yùn)行 大神幫忙看下

溫溫醬 2022-01-21 15:15:00
public class LinkedList <E> { private class Node { public E e; public Node next; public Node(E e, Node next) { this.e = e; this.next = next; } public Node(E e) { this(e, null); } public Node() { this(null, null); } @Override public String toString() { return e.toString(); } } private Node dummyHead; private int size; public LinkedList(){ dummyHead = new Node(null,null); size = 0; } public int getSize(){ return size; } public boolean isEmpty(){ return size == 0; } public void addFirst(E e){ add(0,e); } public void add(int index,E e){ if (index < 0 || index >size ) throw new IllegalArgumentException("add failed.Illegal index."); Node prev = dummyHead; for(int i = 0; i < index; i++) prev = prev.next; Node node = new Node(e); node.next = prev.next; prev.next = node; size++; } public void addLast(E e){ add(size,e); } public E get(int index){ if(index < 0 || index >= size) throw new IllegalArgumentException("get failed. Illegal index."); Node cur = dummyHead.next; for(int i = 0; i < index ; i ++) cur = cur.next; return cur.e; } public E getFirst(){ return get(0); } public E getLast(){ return get( size - 1); } public void set(int index,E e){ if(index < 0 || index >= size) throw new IllegalArgumentException("set failed. Illegal index."); Node cur = dummyHead.next; for(int i = 0; i < index; i++) cur = cur.next; cur.e = e; } public boolean contains(E e){ Node cur = dummyHead.next; while(cur != null){ if(cur.e.equals(e)) return true; cur = cur.next; } return false; }}
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

你在for循環(huán)里 System.out.println(linkedList.get(i)); 就能打印出0,1,2,3,4來了

查看完整回答
反對 回復(fù) 2022-01-23
?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊

特意把這個(gè)圖片下載下來看了,Process finished with exit code 0 意味著你的程序正常執(zhí)行完畢并退出。很正常的運(yùn)行了呀

查看完整回答
反對 回復(fù) 2022-01-23
  • 2 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號