Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1.  
  2. import java.util.LinkedList;
  3.  
  4. public class LinkedListJono {
  5.     LinkedList<Integer> table = new LinkedList();
  6.     int head;
  7.     int tail;
  8.  
  9.     LinkedListJono(){
  10.         head = 0; tail = 0;
  11.     }
  12.  
  13.     boolean empty(){
  14.         return head == tail;
  15.     }
  16.  
  17.     void enqueue(int x){
  18.         table.add(tail, x);
  19.         tail++;
  20.         if(tail == table.size()) tail = 0;
  21.     }
  22.  
  23.     int dequeue(){
  24.         int pois = table.get(head);
  25.         head++;
  26.         if(head == table.size()) head = 0;
  27.         return pois;
  28.     }
  29.  
  30.     int size(){
  31.         return table.size();
  32.     }
  33.  
  34.  
  35.     public static void main(String[] args) {
  36.         LinkedListJono jono = new LinkedListJono();
  37.         int koko = 1000000;
  38.         long alku = System.currentTimeMillis();
  39.         for (int i = 0; i < koko; i++) {
  40.             jono.enqueue(i);
  41.          }
  42.         long loppu = System.currentTimeMillis();
  43.         System.out.println("Enqueue: "+koko+" syötteellä kesti "+(loppu-alku)+"ms");
  44.  
  45.         alku = System.currentTimeMillis();
  46.         while(!jono.empty()){
  47.             jono.dequeue();
  48.         }
  49.         loppu = System.currentTimeMillis();
  50.         System.out.println("Dequeue: "+koko+" syötteellä kesti "+(loppu-alku)+"ms");
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement