Java数据结构和算法 - 链表实现栈和队列

2021/04/14 Algorithm 共 557 字,约 2 分钟
Bob.Zhu

链表实现栈

public class LinkStack {

  private LinkList thisList;

  public LinkStack(){
    thisList = new LinkList();
  }

  public void push(int data){
    thisList.insertFirst(data);
  }

  public int pop(){
    return thisList.deleteFirst().data;
  }

  public boolean isEmpty(){
    return thisList.isEmpty();
  }

  public void display(){
    thisList.display();
  }

}

链表实现队列

public class LinkQueue {
  private DoubleEndedLink theList;

  public LinkQueue() {
    theList = new DoubleEndedLink();
  }

  public void insert(int data) {
    theList.insertLast(data);
  }

  public int remove() {
    return theList.deleteFirst().data;
  }

  public boolean isEmpty() {
    return theList.isEmpty();
  }

}

参考资料

文档信息

Search

    Table of Contents