Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Last active July 14, 2021 16:45
Show Gist options
  • Save AahanSingh/c8c7aaf08968b27fa6f4a60132fc9ed8 to your computer and use it in GitHub Desktop.
Save AahanSingh/c8c7aaf08968b27fa6f4a60132fc9ed8 to your computer and use it in GitHub Desktop.
Linked List StackOperations.go
func (s *stack) push(x int) {
linkedlist.InsertAtStart(&s.top, x)
s.stackSize++
}
func (s *stack) pop() int {
if s.isEmpty() {
fmt.Println("Stack Underflow.")
return -1
}
val := (*s).top.Data
linkedlist.DeleteFirstInPlace(&s.top)
s.stackSize--
return val
}
func (s *stack) peek() int {
if s.isEmpty() {
fmt.Print("Underflow.")
return -1
}
return s.top.Data
}
func (s *stack) isEmpty() bool {
return s.top == nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment