All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.psjava.ds.stack.StackFactoryUsingDynamicArray Maven / Gradle / Ivy

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