SHOW:
|
|
- or go back to the newest paste.
| 1 | public class TombSor implements Sor {
| |
| 2 | public int[] tomb; | |
| 3 | public int ptr; | |
| 4 | ||
| 5 | public TombSor() {
| |
| 6 | tomb = new int[ 100 ]; | |
| 7 | ptr = 0; | |
| 8 | } | |
| 9 | ||
| 10 | - | public TombSor( int size ) {
|
| 10 | + | public TombSor( int size ) throws Exception {
|
| 11 | - | if( size < 0 ) {
|
| 11 | + | if( size <= 0 ) {
|
| 12 | - | tomb = new int[ 100 ]; |
| 12 | + | throw new Exception( "Hibas a tomb merete" ); |
| 13 | } | |
| 14 | else {
| |
| 15 | tomb = new int[ size ]; | |
| 16 | } | |
| 17 | ptr = 0; | |
| 18 | } | |
| 19 | ||
| 20 | public boolean isUres() {
| |
| 21 | if( ptr == 0 ) {
| |
| 22 | return true; | |
| 23 | } | |
| 24 | return false; | |
| 25 | } | |
| 26 | ||
| 27 | - | public int kivesz() {
|
| 27 | + | public int kivesz() throws Exception{
|
| 28 | int tmp; | |
| 29 | if( isUres() ) {
| |
| 30 | - | System.out.println( "Nincs mit kivenni, a sor ures!" ); |
| 30 | + | throw new Exception( "Nincs mit kivenni, a sor ures!" ); |
| 31 | - | return 0; |
| 31 | + | |
| 32 | tmp = tomb[ ptr - 1 ]; | |
| 33 | tomb[ --ptr ] = 0; | |
| 34 | return tmp; | |
| 35 | } | |
| 36 | ||
| 37 | public void betesz( int num ) {
| |
| 38 | if( ptr == tomb.length ) {
| |
| 39 | tomb = Arrays.copyOf( tomb , tomb.length * 2 ); | |
| 40 | } | |
| 41 | tomb[ ptr ] = num; | |
| 42 | ++ptr; | |
| 43 | } | |
| 44 | } |