Created
March 10, 2012 13:54
-
-
Save paul-ihnatolia/2011481 to your computer and use it in GitHub Desktop.
Stack for labwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.uzhnu.homework.stack; | |
public class Stack { | |
private String [] strArray; //new arr | |
private int currEl; //pointer to Stack top | |
private static int defaultSize=10; | |
Stack(){ | |
this.strArray = new String[defaultSize]; | |
this.currEl=0; | |
} | |
Stack(String [] mas){ | |
this.strArray = mas; | |
this.currEl=strArray.length-1; | |
} | |
public boolean push(String string)throws Exception{ | |
if(currEl==strArray.length-1) | |
throw new Exception("Stack is Overflowed!"); | |
strArray[++currEl] = string; | |
return true; | |
} | |
public String pop()throws Exception{ | |
if(currEl==0) | |
throw new Exception("Stack is empty!"); | |
return strArray[currEl--]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment