最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

運(yùn)行代碼無(wú)效果

為什么代碼提交沒(méi)錯(cuò),但是運(yùn)行點(diǎn)擊按鈕沒(méi)有效果??

正在回答

2 回答

public class MyLinkedList<E> extends AbstractList<E>{
?? ?private Node<E> head, tail;
?? ?private int size = 0;
?? ?public MyLinkedList() {
?? ??? ?
?? ?}
?? ?
?? ?public E getFirst() {
?? ??? ?if (size == 0) {
?? ??? ??? ?return null;
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?return head.element;
?? ??? ?}
?? ?}

?? ?public E getLast() {
?? ??? ?if (size == 0) {
?? ??? ??? ?return null;
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?return tail.element;
?? ??? ?}
?? ?}
?? ?
?? ?public void addFirst(E e) {
?? ??? ?Node<E> newNode = new Node<E>(e); // Create a new Node
?? ??? ?newNode.next = head;// link the new node with the head
?? ??? ?head = newNode; // head points to the new node
?? ??? ?size++;
?? ??? ?
?? ??? ?if (tail == null) // the new node is the only node in list
?? ??? ??? ?tail = head;
?? ?}
?? ?
?? ?public void addLast(E e) {
?? ??? ?Node<E> newNode = new Node<E>(e); // Create a new Node for e
?? ??? ?
?? ??? ?if (tail == null) {
?? ??? ??? ?head = tail = newNode; // The only node in list
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?tail.next = newNode; // link the new with the last node
?? ??? ??? ?tail = tail.next; // tail now points to the last node
?? ??? ?}
?? ??? ?
?? ??? ?size++; // Increase size
?? ?}
?? ?
?? ?public void add(int index, E e) {
?? ??? ?if (index == 0) addFirst(e);// Insert first
?? ??? ?else if (index >= size) addLast(e); //Insert last
?? ??? ?else { // Insert in the middle
?? ??? ??? ?Node<E> current = head;
?? ??? ??? ?for (int i = 1; i < index; i++)
?? ??? ??? ??? ?current = current.next;
?? ??? ??? ?Node<E> temp = current.next;
?? ??? ??? ?current.next = new Node<E>(e);
?? ??? ??? ?(current.next).next = temp;
?? ??? ??? ?size++;
?? ??? ?}
?? ?}
?? ?
?? ?public E removeFirst() {
?? ??? ?if (size == 0)
?? ??? ??? ?return null;
?? ??? ?else if (size == 1)
?? ??? ?{
?? ??? ??? ?Node<E> temp = head;
?? ??? ??? ?head = tail = null;
?? ??? ??? ?size? = 0;
?? ??? ??? ?return temp.element;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?Node<E> temp = head;?? ?
?? ??? ??? ?head = head.next;
?? ??? ??? ?size--;
?? ??? ??? ?return temp.element;
?? ??? ?}?? ?
?? ?}
?? ?
?? ?public E removeLast() {
?? ??? ?if (size == 0)
?? ??? ??? ?return null; // Nothing to remove
?? ??? ?else if (size == 1) // only one element in the list
?? ??? ?{
?? ??? ??? ?Node<E> temp = head;
?? ??? ??? ?head = tail = null; // list becomes empty
?? ??? ??? ?size = 0;
?? ??? ??? ?return temp.element;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?Node<E> current = head;
?? ??? ??? ?
?? ??? ??? ?for (int j = 0; j < size - 2; j++)
?? ??? ??? ??? ?current = current.next;
?? ??? ??? ?
?? ??? ??? ?Node<E> temp = tail;
?? ??? ??? ?tail = current;
?? ??? ??? ?tail.next = null;
?? ??? ??? ?size--;
?? ??? ??? ?return temp.element;
?? ??? ?}
?? ?}
?? ?
?? ?public E remove(int index) {
?? ??? ?if (index < 0 || index >= size)
?? ??? ??? ?return null; //Out of range
?? ??? ?else if (index == 0)
?? ??? ??? ?return removeFirst(); // Remove first
?? ??? ?else if (index == size - 1)
?? ??? ??? ?return removeLast(); // Remove last
?? ??? ?else {
?? ??? ??? ?Node<E> previous = head;?? ?
?? ??? ??? ?for (int i = 1; i <index; i++) {
?? ??? ??? ??? ?previous = previous.next;
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?Node<E> current = previous.next;
?? ??? ??? ?previous.next = current.next;
?? ??? ??? ?size--;
?? ??? ??? ?return current.element;
?? ??? ?}
?? ?}
?? ?
?? ?public String toString() {
?? ??? ?StringBuilder result = new StringBuilder("[");
?? ??? ?
?? ??? ?Node<E> current = head;
?? ??? ?for (int i = 0; i < size; i++) {
?? ??? ??? ?result.append(current.element);
?? ??? ??? ?current = current.next;
?? ??? ??? ?if (current != null) {
?? ??? ??? ??? ?result.append(", ");
?? ??? ??? ?}
?? ??? ??? ?else {
?? ??? ??? ??? ?result.append("]");
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?return result.toString();
?? ?}
?? ?
?? ?public void clear() {
?? ??? ?head = tail = null;
?? ?}
?? ?
?? ?public boolean contains(Object o) {
?? ??? ?System.out.println("Implementation left as an exercise");
?? ??? ?return true;
?? ?}
?? ?
?? ?public E get(int index) {
?? ??? ?System.out.println("Implementation left as an exercise");
?? ??? ?return null;
?? ?}
?? ?
?? ?public int indexOf(Object o) {
?? ??? ?System.out.println("Implementation left as an exercise");
?? ??? ?return 0;
?? ?}
?? ?
?? ?public int lastIndexOf(Object o) {
?? ??? ?System.out.println("Implementation left as an exercise");
?? ??? ?return 0;
?? ?}
?? ?
?? ?public E set(int index, E e) {
?? ??? ?System.out.println("Implementation left as an exercise");
?? ??? ?return null;
?? ?}
?? ?
?? ?private static class Node<E> {
?? ??? ?E element;
?? ??? ?Node<E> next;
?? ??? ?
?? ??? ?public Node(E element) {
?? ??? ??? ?this.element = element;
?? ??? ?}
?? ?}

?? ?@Override
?? ?public int size() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?return 0;
?? ?}
}

0 回復(fù) 有任何疑惑可以回復(fù)我~

你代碼怎么寫的?

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JavaScript入門篇
  • 參與學(xué)習(xí)       741554    人
  • 解答問(wèn)題       9869    個(gè)

JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門

進(jìn)入課程

運(yùn)行代碼無(wú)效果

我要回答 關(guān)注問(wèn)題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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