Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. public class Queue {
  2.   private int[] list;
  3.   private int i=0;
  4.  
  5.   public Queue(){
  6.     Init();      
  7.   }
  8.  
  9.   public void Init(){
  10.     list=new int[10];
  11.   }
  12.  
  13.   public int FindLast(){
  14.     int a=-1;
  15.     for(int i=9;i>=0;i--)
  16.       if (list[i]!=0) {
  17.         a=i;
  18.         break;
  19.       }
  20.     return a;  
  21.   }
  22.  
  23.   public void Enqueue(int x){
  24.     if(i+1<10){
  25.       for(int a=8;a>=0;a--) list[a+1]=list[a];  
  26.       list[0]=x;
  27.       i++;
  28.     }
  29.     else
  30.       System.out.println("Schlange voll.");
  31.   }
  32.  
  33.   public void Dequeue(){
  34.     if(!Empty())
  35.       list[FindLast()]=0;  
  36.     else
  37.       System.out.println("Schlange leer.");
  38.   }
  39.  
  40.   public int Front(){
  41.     if(!Empty())
  42.       return list[0];
  43.     else{
  44.       System.out.println("Schlange leer.");
  45.       return -1;
  46.     }
  47.   }
  48.  
  49.   public Boolean Empty(){
  50.     if(i==0)
  51.       return true;
  52.     else
  53.       return false;
  54.   }
  55.  
  56.   public void Show(){
  57.     System.out.println("");  
  58.     if(!Empty())
  59.       for(int a=0;a<10;a++)
  60.         if(a<9)System.out.print(list[a]+",");
  61.         else System.out.print(list[a]);
  62.     else
  63.       System.out.println("Schlange leer.");
  64.   }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement