Class DLinked_StackGeneric<E>
java.lang.Object
DLinked_StackGeneric<E>
- Type Parameters:
E- Type of element stored in the list.
- All Implemented Interfaces:
StackGeneric_Interface<E>
A generic stack implemented with a doubly linked list.
- Author:
- Dr. Lillis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all elements from this stack.booleanisEmpty()Returns true if this stack is empty, returns false otherwise.peek()Returns but does not remove the element at the top of this stack.pop()Removes and returns the element at the top of this stack.voidAdds the given element to the top of the stack.intsize()Returns the number of elements in this stack.toString()Returns a string containing each element in this list, separated by commas, enclosed in square brackets.
-
Constructor Details
-
DLinked_StackGeneric
public DLinked_StackGeneric()Constructs an empty stack.
-
-
Method Details
-
push
Description copied from interface:StackGeneric_InterfaceAdds the given element to the top of the stack.- Specified by:
pushin interfaceStackGeneric_Interface<E>- Parameters:
element- element to be added to the top of this stack
-
clear
public void clear()Description copied from interface:StackGeneric_InterfaceRemoves all elements from this stack. If the stack is empty, nothing is done.- Specified by:
clearin interfaceStackGeneric_Interface<E>
-
pop
Description copied from interface:StackGeneric_InterfaceRemoves and returns the element at the top of this stack.- Specified by:
popin interfaceStackGeneric_Interface<E>- Returns:
- the element at the top of this stack
- Throws:
EmptyStackException- if this stack is empty.
-
isEmpty
public boolean isEmpty()Description copied from interface:StackGeneric_InterfaceReturns true if this stack is empty, returns false otherwise.- Specified by:
isEmptyin interfaceStackGeneric_Interface<E>- Returns:
- true if this stack is empty, returns false otherwise
-
peek
Description copied from interface:StackGeneric_InterfaceReturns but does not remove the element at the top of this stack.- Specified by:
peekin interfaceStackGeneric_Interface<E>- Returns:
- the element at the top of this stack.
- Throws:
EmptyStackException- if this stack is empty.
-
size
public int size()Description copied from interface:StackGeneric_InterfaceReturns the number of elements in this stack.- Specified by:
sizein interfaceStackGeneric_Interface<E>- Returns:
- number of elements in this stack
-
toString
Description copied from interface:StackGeneric_InterfaceReturns a string containing each element in this list, separated by commas, enclosed in square brackets. The top of the stack is indicated to the left. For example: TOS [e1, e1, e3]- Specified by:
toStringin interfaceStackGeneric_Interface<E>- Overrides:
toStringin classObject- Returns:
- a string representation of this list.
-