Skip to content

Commit

Permalink
Create 225-Implement-Stack-using-Queues.go
Browse files Browse the repository at this point in the history
  • Loading branch information
razer96 committed Dec 16, 2022
1 parent 270330a commit b3d5c47
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions go/225-Implement-Stack-using-Queues.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type MyStack struct {
queue []int
}


func Constructor() MyStack {
return MyStack{}
}


func (this *MyStack) Push(x int) {
this.queue = append(this.queue, x)
}


func (this *MyStack) Pop() int {
if this.Empty() {
return 0
}

elem := this.queue[len(this.queue) - 1]

this.queue = this.queue[:len(this.queue) - 1]

return elem
}


func (this *MyStack) Top() int {
if this.Empty() {
return 0
}

return this.queue[len(this.queue) - 1]
}


func (this *MyStack) Empty() bool {
return len(this.queue) == 0
}

0 comments on commit b3d5c47

Please sign in to comment.