public class ArrayListStack extends Object
ArrayListStack
class represents a last-in-first-out
(LIFO) stack of objects. It encapsulates class ArrayList with four
operations that allow a list to be treated as a stack. The usual
push and pop operations are provided, as well as a
method to peek at the top item on the stack, and a method to test
for whether the stack is empty
When a stack is first created, it contains no items.
Constructor and Description |
---|
ArrayListStack()
Creates a stack with a default size
|
ArrayListStack(int size)
Creates a stack with the given initial size
|
Modifier and Type | Method and Description |
---|---|
boolean |
empty()
Tests if this stack is empty.
|
Object |
peek()
Looks at the object at the top of this stack without removing it
from the stack.
|
Object |
pop()
Removes the object at the top of this stack and returns that
object as the value of this function.
|
void |
push(Object obj)
Pushes an item onto the top of this stack.
|
int |
size()
Provides the current size of the stack.
|
public ArrayListStack(int size)
public ArrayListStack()
public int size()
public void push(Object obj)
obj
- the object to be pushed onto this stack.ArrayList.add(E)
public Object pop()
public boolean empty()
true
if and only if this stack contains
no items; false
otherwise.public Object peek()
Copyright © 2018. All rights reserved.