Skip to content

Instantly share code, notes, and snippets.

@paul-ihnatolia
Created March 10, 2012 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-ihnatolia/2011481 to your computer and use it in GitHub Desktop.
Save paul-ihnatolia/2011481 to your computer and use it in GitHub Desktop.
Stack for labwork
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