-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.go
More file actions
67 lines (56 loc) · 935 Bytes
/
Copy pathstack.go
File metadata and controls
67 lines (56 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
// FILO stack
type Line struct {
}
type Stack struct {
data []*Line
top int
size int
}
func NewStack(size int) *Stack {
return &Stack{make([]*Line, size), 0, size}
}
func (s *Stack) Len() int {
return len(s.data)
}
func (s *Stack) Cap() int {
return cap(s.data)
}
func (s *Stack) IsEmpty() bool {
return s.top == 0
}
func (s *Stack) Push(line *Line) {
if s.top < s.size {
s.data[s.top] = line
s.top += 1
} else {
panic("Error :: We need to allocate more Stack space")
}
}
func (s *Stack) Pop() *Line {
s.top -= 1
if s.top < 0 {
return nil
}
deleted := s.data[s.top]
s.data[s.top] = nil
return deleted
}
func (s *Stack) GetLast() *Line {
if s.IsEmpty() {
return nil
}
return s.data[s.top-1]
}
func (s *Stack) MakeNULL() bool {
if s.IsEmpty() {
return false
}
for i := s.top; i > 0; i-- {
s.Pop()
//e := s.Pop()
//e.texture.Destroy()
//e.texture = nil
}
return true
}