当前位置:网站首页>Implementation of stack
Implementation of stack
2022-07-03 19:47:00 【Follow the road to the end】
We need to implement the following functions :
push() Stack method
pop() Stack method
top() Get stack top value
size() Get the number of elements of the stack
clear() Empty stack
class Stack {
constructor () {
// Store stack data
this.data = []
// Number of recorded data
this.count = 0
}
// Stack method
push (item) {
// this.data.push(item)
// this.data[this.data.length] = item
this.data[this.count] = item
this.count++
}
// Stack method
pop () {
if (this.isEmpty()) {
console.log(' The stack is empty. ')
return
}
const temp = this.data[this.count - 1]
delete this.data[--this.count]
return temp
}
// Check if the stack is empty
isEmpty () {
return this.count === 0
}
// Get stack top element
top () {
if (this.isEmpty()) {
console.log(' The stack is empty. ')
return
}
return this.data[this.count - 1]
}
// Get the number of elements
size () {
return this.count
}
// Empty stack
clear () {
this.data = []
this.count = 0
}
}1
边栏推荐
- Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
- 02 -- QT OpenGL drawing triangle
- Acquisition and transmission of parameters in automatic testing of JMeter interface
- Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
- Sentinel source code analysis part II - sentinel dashboard console startup and configuration
- I study database at station B (4): DQL
- Merge K ascending linked lists
- BOC protected phenylalanine zinc porphyrin (Zn · TAPP Phe BOC) / iron porphyrin (Fe · TAPP Phe BOC) / nickel porphyrin (Ni · TAPP Phe BOC) / manganese porphyrin (Mn · TAPP Phe BOC) Qiyue Keke
- Redis master-slave synchronization, clustering, persistence
- Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro
猜你喜欢

第一章:拓广同码小数和s(d, n)

Flume learning notes

Chapter 1: find the algebraic sum of odd factors, find the same decimal sum s (D, n), simplify the same code decimal sum s (D, n), expand the same code decimal sum s (D, n)

第一章: 舍罕王失算

2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)

2022-06-25 advanced network engineering (XI) IS-IS synchronization process of three tables (neighbor table, routing table, link state database table), LSP, cSNP, psnp, LSP

Acquisition and transmission of parameters in automatic testing of JMeter interface

kubernetes集群搭建efk日志收集平台

5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes

Chapitre 1: le roi de shehan a mal calculé
随机推荐
The simplicity of laravel
What is the difference between a kill process and a close process- What are the differences between kill process and close process?
kubernetes集群搭建efk日志收集平台
Microservice framework - frequently asked questions
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)
03 -- QT OpenGL EBO draw triangle
How to check the permission to write to a directory or file- How do you check for permissions to write to a directory or file?
交叉编译Opencv带Contrib
第一章:拓广同码小数和s(d, n)
Find a line in a file and remove it
About unregistered transfer login page
The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
Strict data sheet of new features of SQLite 3.37.0
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
Chapter 1: find the factorial n of n!
Make a simple text logo with DW
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
UE source code analysis: uccharactermovementcomponent - rootmotion
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding