We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 28c14d7 commit e05bbc7Copy full SHA for e05bbc7
go-note/algorithms.rst
@@ -3,6 +3,37 @@
3
Go 算法和数据结构
4
=====================================================================
5
6
+Stack
7
+--------------------------------------------------
8
+
9
+.. code-block:: go
10
11
+ type Stack struct {
12
+ st []int
13
+ }
14
15
+ func NewStack() *Stack {
16
+ return &Stack{st:make([]int,0)}
17
18
+ func (s *Stack) Push(x int) {
19
+ s.st = append(s.st, x)
20
21
22
+ func (s *Stack) Peek() int{
23
+ return s.st[len(s.st)-1]
24
25
26
+ func (s *Stack) Pop() int{
27
+ n := len(s.st)
28
+ top := s.st[n-1]
29
+ s.st = s.st[:n-1]
30
+ return top
31
32
33
+ func (s *Stack) Empty() bool{
34
+ return len(s.st) == 0
35
36
37
Queue
38
--------------------------------------------------
39
0 commit comments