Package dsa
Class LinkedStack<Item>
- java.lang.Object
-
- dsa.LinkedStack<Item>
-
-
Constructor Summary
Constructors Constructor Description LinkedStack()
Constructs an empty stack.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isEmpty()
Returnstrue
if this stack is empty, andfalse
otherwise.Iterator<Item>
iterator()
Returns an iterator to iterate over the items in this stack in LIFO order.static void
main(String[] args)
Unit tests the data type.Item
peek()
Returns the item at the top of this stack.Item
pop()
Removes and returns the item at the top of this stack.void
push(Item item)
Addsitem
to the top of this stack.int
size()
Returns the number of items in this stack.String
toString()
Returns a string representation of this stack.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Description copied from interface:Stack
Returnstrue
if this stack is empty, andfalse
otherwise.
-
size
public int size()
Description copied from interface:Stack
Returns the number of items in this stack.
-
push
public void push(Item item)
Description copied from interface:Stack
Addsitem
to the top of this stack.
-
peek
public Item peek()
Description copied from interface:Stack
Returns the item at the top of this stack.
-
pop
public Item pop()
Description copied from interface:Stack
Removes and returns the item at the top of this stack.
-
iterator
public Iterator<Item> iterator()
Returns an iterator to iterate over the items in this stack in LIFO order.
-
toString
public String toString()
Returns a string representation of this stack.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-