Skip to content

Instantly share code, notes, and snippets.

@HamzaAnis
Created February 8, 2019 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HamzaAnis/7f9a8867a50db7e6540f2307c2c594c1 to your computer and use it in GitHub Desktop.
Save HamzaAnis/7f9a8867a50db7e6540f2307c2c594c1 to your computer and use it in GitHub Desktop.
Stack And Queue
type Queue []*Node
func (q *Queue) Push(n *Node) {
*q = append(*q, n)
}
func (q *Queue) Pop() (n *Node) {
n = (*q)[0]
*q = (*q)[1:]
return
}
func (q *Queue) Len() int {
return len(*q)
}
type Stack []*Node
func (q *Stack) Push(n *Node) {
*q = append(*q, n)
}
func (q *Stack) Pop() (n *Node) {
x := q.Len() - 1
n = (*q)[x]
*q = (*q)[:x]
return
}
func (q *Stack) Len() int {
return len(*q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment