Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- public class LinkedListJono {
- LinkedList<Integer> table = new LinkedList();
- int head;
- int tail;
- LinkedListJono(){
- head = 0; tail = 0;
- }
- boolean empty(){
- return head == tail;
- }
- void enqueue(int x){
- table.add(tail, x);
- tail++;
- if(tail == table.size()) tail = 0;
- }
- int dequeue(){
- int pois = table.get(head);
- head++;
- if(head == table.size()) head = 0;
- return pois;
- }
- int size(){
- return table.size();
- }
- public static void main(String[] args) {
- LinkedListJono jono = new LinkedListJono();
- int koko = 1000000;
- long alku = System.currentTimeMillis();
- for (int i = 0; i < koko; i++) {
- jono.enqueue(i);
- }
- long loppu = System.currentTimeMillis();
- System.out.println("Enqueue: "+koko+" syötteellä kesti "+(loppu-alku)+"ms");
- alku = System.currentTimeMillis();
- while(!jono.empty()){
- jono.dequeue();
- }
- loppu = System.currentTimeMillis();
- System.out.println("Dequeue: "+koko+" syötteellä kesti "+(loppu-alku)+"ms");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement