数据结构及算法之栈(基于链表)讲解

1,具体实现

package com.dream21th.algorithmicdatastructure.linkedlist;

/**
 * @Auther: hp
 * @Date: 2019/9/13 20:19
 * @Description:
 */
public class LinkedListStack implements Stack {

    private LinkedList linkedList=new LinkedList<>();
    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public void push(E e) {
       linkedList.addFirst(e);
    }

    @Override
    public E pop() {
        return linkedList.removeFirst();
    }

    @Override
    public E peek() {
        return linkedList.getFirst();
    }
}

 

你可能感兴趣的:(数据结构与算法)