Created
February 8, 2019 03:21
-
-
Save HamzaAnis/7f9a8867a50db7e6540f2307c2c594c1 to your computer and use it in GitHub Desktop.
Stack And Queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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