Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1fecd0

Browse files
committed
simple stack implementation
1 parent15e7872 commita1fecd0

5 files changed

+29
-0
lines changed
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Each data structure can be implemented by the different method. We can treat stack as a subclass of Array. So we take the array for example here.
3+
4+
classStack{
5+
6+
constructor(){
7+
this.stack=[]
8+
}
9+
10+
push(item){
11+
this.stack.push(item)
12+
}
13+
14+
pop(item){
15+
this.stack.pop(item)
16+
}
17+
18+
peek(item){
19+
this.stack[this.getCount()-1]
20+
}
21+
22+
getCount(){
23+
returnthis.stack.length
24+
}
25+
26+
isEmpty(){
27+
returnthis.stack.length===0
28+
}
29+
}
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp