自訂LinkedList實現

來源:互聯網
上載者:User

標籤:http   os   cti   代碼   for   io   

1. [代碼]首先是借口定義
* @author xzf
public interface MyDeque<E> {
* insert the specified element at the front of this deque if it is possible
* to do so immediately without violating capacity restrictions.
@param e the element to add
void addFirst(E e);
* insert the specified element at the end of this deque if it is possible
* to do so immediately without violating capacity restrictions.
* @param e the element to add
void addLast(E e);
* @return the head of this deque
E removeFirst();
* @return the tail of this deque
E removeLast();
* insert the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) if it is possible
* to do so immediately without violating capacity restrictions.
* @return true upon success
boolean add(E e);
* retrieve and remove the head of this queue represented by this deque
* (in other words, the first element of this deque).
* @return the head of the queue represented by this deque
* push an element onto the stack represented by this deque
* (in other words, at the head of this deque) if it is possible
to do so immediately without violating capacity restrictions.
* @param e the element to push
void push(E e);
* pop an element from the stack represented by this deque. In other words,
* removes and returns the first element of this deque.
* @return the element at the front of this deque
* return the number of elements of this dceque.
* @return the number of elements of this dceque
2. [代碼]自訂LinkedList實作類別
view sourceprint?
* @author xzf
* @param <E>
public class MyLinkedList<E> implements MyDeque<E>{
private Entry<E> header;
private int size;
public MyLinkedList()
header = new Entry<E>(null, null, null);
size = 0;
header.next = header.privious = header;
* insert the specified element at the front of this deque if it is possible
* to do so immediately without violating capacity restrictions.
* @param e the element to add
public void addFirst(E e) {
addBefore(e, header.next);
* insert the specified element at the end of this deque if it is possible
* to do so immediately without violating capacity restrictions.
@param e the element to add
public void addLast(E e) {
addBefore(e, header);
* retrieve and remove the first element of this deque.
* @return the head of this deque
public E removeFirst() {
return remove(header.next);
* @return the tail of this deque
public E removeLast() {
return remove(header.privious);
* insert the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) if it is possible
* to do so immediately without violating capacity restrictions.
* @return true upon success
public boolean add(E e) {
addBefore(e, header);http://www.huiyi8.com/jiaoben/ JQuery特效
* retrieve and remove the head of this queue represented by this deque
* (in other words, the first element of this deque).
* @return the head of the queue represented by this deque
public E remove() {
return removeFirst();
* push an element onto the stack represented by this deque
* (in other words, at the head of this deque) if it is possible
* to do so immediately without violating capacity restrictions.
* @param e the element to push

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.