Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TombSor implements Sor {
- public int[] tomb;
- public int ptr;
- public TombSor() {
- tomb = new int[ 100 ];
- ptr = 0;
- }
- public TombSor( int size ) throws Exception {
- if( size <= 0 ) {
- throw new Exception( "Hibas a tomb merete" );
- }
- else {
- tomb = new int[ size ];
- }
- ptr = 0;
- }
- public boolean isUres() {
- if( ptr == 0 ) {
- return true;
- }
- return false;
- }
- public int kivesz() throws Exception{
- int tmp;
- if( isUres() ) {
- throw new Exception( "Nincs mit kivenni, a sor ures!" );
- }
- tmp = tomb[ ptr - 1 ];
- tomb[ --ptr ] = 0;
- return tmp;
- }
- public void betesz( int num ) {
- if( ptr == tomb.length ) {
- tomb = Arrays.copyOf( tomb , tomb.length * 2 );
- }
- tomb[ ptr ] = num;
- ++ptr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment