package stack;
public class MyImplStack<T> implements MyStack<T>{
private Object[] obj = new Object[1];
private int size = 0;
@Override
public void clear() {
for(int i = 0; i < size; i++){
obj[i] = null;
}
size = 0;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean push(T data) {
if(size >= obj.length){
resize();
}
obj[size ++] = data;
return true;
}
@Override
public void resize() {
Object[] temp = new Object[obj.length*3/2+1];
for(int i= 0;i<size;i++){
temp[i] = obj[i];
obj[i]=null;
}
obj = temp;
}
@Override
public T pop() {
if(size == 0){
return null;
}
return (T) obj[--size];
}
@Override
public int length() {
return obj.length;
}
}
public class MyImplStack<T> implements MyStack<T>{
private Object[] obj = new Object[1];
private int size = 0;
@Override
public void clear() {
for(int i = 0; i < size; i++){
obj[i] = null;
}
size = 0;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean push(T data) {
if(size >= obj.length){
resize();
}
obj[size ++] = data;
return true;
}
@Override
public void resize() {
Object[] temp = new Object[obj.length*3/2+1];
for(int i= 0;i<size;i++){
temp[i] = obj[i];
obj[i]=null;
}
obj = temp;
}
@Override
public T pop() {
if(size == 0){
return null;
}
return (T) obj[--size];
}
@Override
public int length() {
return obj.length;
}
}