Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

StackAsMyArrayList

public class StackAsMyArrayList<E> 
{   
	MyArrayList<E> theStack;
    public StackAsMyArrayList()
    {  theStack = new MyArrayList<E>();       
    }
	
    public void push(E newElement) //insert at end of array!
    {  
		   if (!theStack.checkSpace())
		   throw new IndexOutOfBoundsException
                    ("Stack out of bounds");
		   theStack.add(theStack.getSize(),newElement);
    }
	
	public E pop() //remove end of array
    {  
		E temp = null;
		
		boolean isDone = false;
		if (theStack.getSize() > 0)
			temp=theStack.remove(theStack.getSize()-1);
		return temp; // temp will be null in special case of empty list
    }
    
	public String toString()
	{
		return theStack.toString();
	}
   
}//end class
Comment

PREVIOUS NEXT
Code Example
Java :: java method parameters 
Java :: java break and continue 
Java :: how to find the length of an array in java 
Java :: text field mouse event java 
Java :: array of arrays java 
Java :: initializing list in java 
Java :: java anonmyous array eg 
Java :: pass a list of string as PathVariable to api spring boot 
Java :: get max of array java 
Java :: kkkkkkkkkkkkkk 
Java :: nqueen problem with python 
Java :: bukkit console filter 
Java :: keep jframe on top 
Java :: Number formatting java with locale 
Java :: .jar window immediately closes on doubleclick 
Java :: how to create a subclass in java 
Java :: how to call a non static method 
Java :: get host from request object java 
Java :: mod 10e9+7 in java 
Java :: Java Create a LinkedHashSet 
Java :: java sub function 
Java :: android java turn off night mode 
Java :: csv compare 
Java :: generic method lambda java 
Java :: change fab image programatically 
Java :: object null java 
Java :: is c# similar to java 
Java :: java random number generator 
Java :: fragment call activity 
Java :: change element in array java 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =