java - FIFO queue with circular list -


i have created queue implementation using single connection list.in code using 2 pointers (first,last) define start , end of queue. code :

import java.io.printstream; import java.util.* /** * @author justin bieber */ public class stringqueueimpl<t> implements stringqueue {  private int total;         // number of elements on queue private node head;    // beginning of queue private node tail;     // end of queue  private class node {     t ele;     node next;     node(t ele) {     this.ele = ele;     next = null; }  }   /**  * creates empty queue.  */ public stringqueueimpl() {     first = null;     last  = null;     total = 0; }  boolean isempty() {     return (head == null);  }  public <t> void put(t ele) {     node t = tail;     tail = new node(ele);     if (isempty()) head = tail;     else t.next = tail;      total++; }   public t get() {     if (isempty()) throw new nosuchelementexception();     t v = head.ele;     node t = head.next;     head = t;     return v;      total--; }    public t peek() {     if (isempty()) throw new nosuchelementexception();     return head.ele; }  node node = head;  public void printqueue(printstream stream){     while(node != null){         stream.println(node.ele);         stream.flush();         node = node.next;     } }     public int size(){     return total; } } 

my question how can create queue implementation using circular list. (instead of 2 pointers start , end use 1 pointer wich used both start , end of queue).

any apreciated . thank you


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -