org.psjava.ds.stack.StackFactoryUsingDynamicArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of psjava Show documentation
Show all versions of psjava Show documentation
Problem Solving Library for Java
The newest version!
package org.psjava.ds.stack;
import org.psjava.ds.array.DynamicArray;
import org.psjava.ds.array.LastInArray;
public class StackFactoryUsingDynamicArray {
public static StackFactory getInstance() {
return new StackFactory() {
@Override
public Stack create() {
return new Stack() {
DynamicArray a = DynamicArray.create();
@Override
public boolean isEmpty() {
return a.isEmpty();
}
@Override
public T pop() {
return a.removeLast();
}
@Override
public void push(T v) {
a.addToLast(v);
}
@Override
public T top() {
return LastInArray.getLast(a);
}
@Override
public String toString() {
return a.toString();
}
};
}
};
}
private StackFactoryUsingDynamicArray() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy