Stack.java Flashcards

(9 cards)

1
Q

list all of the methods/ attributes of this class

A

*attributes list:
-private Object[] elements;
- private int size = 0;
-private static final int INICIAL_CAPACITY = 3
*public int getSize()
*public void push(Object e)
*public Object pop()
*public Boolean isEmpty()
*private void checkCapacity()
*public String toString($

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

attributes list

A

-public Object[] elements;
-public int size = 0;
-public static final int INICIAL_CAPACITY = 3;

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

constructor

A

Public StackA() {
elements =
new Object[INICIAL_CAPACITY];
}

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

public int getSize()

A

return size;

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

public void push(Object e)

A

checkCapacity();
elements[size++] = e;

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

public Object pop()

A

if (size == 0) {
throw new EmptyStackException();
}
Object result = elements[- -size];
elements[size] = null;
return result;

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

public Boolean isEmpty()

A

if(size == 0) {
return true;
}
else {
return false;
}

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

public void checkCapacity()

A

if(elements.length == size) {
elements = Arrays.copyOf(elements, 2*size +1)
}

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

public String toString()

A

String result = “ “;
for(int i = 0; i<size; i++) {
result += elements[i] + “ “;
return result;

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