Stack and queue as MyArray Flashcards

1
Q

Stack start

A

public class StackAsMyArrayList<E> {
MyArrayList<E> theStack;</E></E>

public StackAsMyArrayList(){
    theStack = new MyArrayList<E>();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

push

A

public void push(E element){
if(theStack.checkSpace()){
theStack.add(theStack.getSize(),element);
}

}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

pop

A

public E pop(){
E temp = null;
if(theStack.getSize() > 0){
temp = theStack.remove(theStack.getSize() - 1);
}
return temp;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

toString stack

A

public String toString(){
return theStack.toString();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Queue start

A

public class QueueAsMyArrayList<E> {
MyArrayList<E> theQueue;</E></E>

public QueueAsMyArrayList(){
    theQueue = new MyArrayList<E>();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

enqueue

A

public void enqueue(E element){
theQueue.add(theQueue.getSize(),element);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

dequeue

A

public E dequeue(){
E temp = null;
if(theQueue.getSize()>0){
temp = theQueue.remove(0);
}
return temp;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

queue toString

A

public String toString(){
return theQueue.toString();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly