Member-only story

Data Structures— Stack

DAOZHUO CHEN
8 min readMay 23, 2024

1. Overview

In computer science, a stack is a linear data structure that can only add and remove data at one end. Traditionally, this end is called the top of the stack, and the other end is called the bottom of the stack if the data cannot be manipulated, just like a stack of books in life.

Photo by Debby Hudson on Unsplash

Provide a stack interface first

public interface Stack<E> {
/**
* Press the element towards the top of the stack
* @param value The value to be pressed in
* @return The press is successfully returned to true, otherwise it is returned to false
*/
boolean push(E value);

/**
* Elements pop up from the top of the stack
* @return A non-empty stack returns the top element of the stack, and a empty stack returns null
*/
E pop();

/**
* Returns to the top element of the stack without popping up
* @return A non-empty stack returns the top element of the stack, and a empty stack returns null
*/
E peek();

/**
* Determine whether the stack is empty
* @return Empty return to true, otherwise return to false
*/
boolean isEmpty();

/**
* Check whether the stack is full
* @return Full return to true, otherwise return to false
*/
boolean isFull();
}

2. Linked list implementation

--

--

DAOZHUO CHEN
DAOZHUO CHEN

Written by DAOZHUO CHEN

Java Development Engineer/Full Stack Engineer/Writer/Trying To Reach 1000 Followers / We Can Follow Each Other On Medium/Share Articles In Various Fields

No responses yet