Queue in Java

Coding implementasi Queue pada Java..
Selamat mencoba....!!!!!

import java.io.*;
import java.util.*;

public class queue{
  LinkedList list;
  String str;
  int num;
  public static void main(String[] args){
    queue q = new queue();
  }
  public queue(){
    try{
      list = new LinkedList();
      InputStreamReader ir = new InputStreamReader(System.in);
      BufferedReader bf = new BufferedReader(ir);
      System.out.println("-----------------------");
      System.out.println("Queue");
      System.out.println("Oleh");
      System.out.println("Ali Efendy.blogspot.com");
      System.out.println("-----------------------");
      System.out.println("");
      System.out.println("");


      System.out.println("Masukkan Jumlah Tumpukkan : ");
      str = bf.readLine();
      if((num = Integer.parseInt(str)) == 0){
        System.out.println("You have entered either zero/null.");
        System.exit(0);
      }
      else{
        System.out.println("Masukkan Angka-angkanya : ");
        for(int i = 0; i < num; i++){
          str = bf.readLine();
          int n = Integer.parseInt(str);
          list.add(n);
        }
      }
      System.out.println("Angka Pertama :" + list.removeFirst());
      System.out.println("");

      System.out.println("Angka terakhir:" + list.removeLast());
      System.out.println("");
      System.out.println("Daftar Urut Tumpuk :");
      System.out.println("");

      while(!list.isEmpty()){
        System.out.print(list.remove() + "\t");
      }
    }
    catch(IOException e){
      System.out.println(e.getMessage() + " is not a legal entry.");
      System.exit(0);
    }
  }
}

0 comments:

Posting Komentar