import java.util.NoSuchElementException;
import java.util.Stack;
public class StackList<T> implements SomeList<E>{
/* Comments
* only use offer(), poll()/remove, isEmpty(), and size() methods*/
private Stack<T> stack=new Stack<T>();
public StackList(){
Stack<T> stack=new Stack<T>();
stack=stack1;
}
public void push(T thing){
stack1.push(thing);
}
@Override
public T pop(){
if(this.isEmpty()){throw new StackOverflowError();}
return stack1.pop();
}
@Override
public void add(T thing) {
stack1.push(thing);
}
public void addFront(T thing) {
int size=this.size();
T[] arr=(T[]) new Object[size];
int i=0;
while(!this.isEmpty()){arr[i]=this.pop();i++;}
}
public T remove(int index) {
if(index>this.size()){throw new IndexOutOfBoundsException();}
else{int sze=this.size();
T[] arr1=(T[])new Object[this.size()];
int i=0;
while(!this.isEmpty()){arr1[i]=this.pop();i++;}
T vre = arr1[index];
for(int j=0;j<size;j++){this.push(arr1[i]);}
return vre;
}
}
public E removeEnd() {
if(this.isEmpty()){return null;}
return this.pop();
}
public E get(int index) {int sze=this.size();
if(index>sze){throw new NoSuchElementException();}
else{
T[] arr2=(T[]) new Object[sze];
int i=0;
while(!this.isEmpty()){arr2[i]=this.pop();i++;}
for(int j=0;j<sze;j++){this.push(arr2[j]);}
return arr2[index];
}
}
public int size() {
return this.size();
}
public boolean isEmpty() {
return this.isEmpty();
}
}
Pyler 0 Junior Poster in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.