Created
December 16, 2010 18:49
-
-
Save Vaysman/743788 to your computer and use it in GitHub Desktop.
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
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package TestFirst; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* | |
* @author User1 | |
*/ | |
public class SuperStack { | |
/* | |
* List<Integer> list убрать совсем. оставить только строку mass. | |
* | |
*/ | |
private List<Integer> list = new ArrayList<Integer>(); | |
private String mass = ""; | |
private int leng = 0; | |
private int index = 0; | |
public boolean isEmpty() { | |
return index==0; | |
} | |
public void push(int i) throws StackFullException { | |
if (index >= 10) { | |
throw new StackFullException(); | |
} | |
/* | |
* какой смысл в этой строчке? | |
*/ | |
Integer j = i; | |
mass=mass+j.toString(); | |
leng = j.toString().length(); | |
list.add(index, leng); | |
index++; | |
} | |
public int pop() throws StackEmptyException{ | |
if (isEmpty()) | |
throw new StackEmptyException(); | |
String st = mass.substring(mass.length()-list.get(index-1), mass.length()); | |
mass = mass.substring(0, mass.length()-list.remove(index-1)); | |
index--; | |
int b = Integer.parseInt(st); | |
return b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
надо переписать эту реализацию.