fatalaa

TombSor

May 13th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  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 ) {
  11.         if( size < 0 ) {
  12.             tomb = new int[ 100 ];
  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() {
  28.         int tmp;
  29.         if( isUres() ) {
  30.             System.out.println( "Nincs mit kivenni, a sor ures!" );
  31.             return 0;
  32.         }
  33.         tmp = tomb[ ptr - 1 ];
  34.         tomb[ --ptr ] = 0;
  35.         return tmp;
  36.     }
  37.    
  38.     public void betesz( int num ) {
  39.         if( ptr == tomb.length ) {
  40.             tomb = Arrays.copyOf( tomb , tomb.length * 2 );
  41.         }
  42.         tomb[ ptr ] = num;
  43.         ++ptr;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment