Assume that there exists an implementation for a linked list which contains the following state:
first // a reference to the first node in the list
and behavior:
addFirst(data)
addLast(data)
removeFirst()
removeLast()
isEmpty()
Write algorithms for functions to this linked list such that a stack can be implemented,
i.e write algorithms which use to above state and behavior to implement:
- push(data)
- pop()
- peek()
(Ensure that you include appropriate return types where necessary)
Updates to this post:
2022 Sept 30 – removed data as a parameter to removeFirst and removeLast()
© 2022 Vedesh Kungebeharry. All rights reserved.