public override CircularQueueItem <T> Dequeue() { //get the tail index as per the circula queue CircularQueueItem <T> tail = this.GetTail(); //check whether the tail is retrived if (tail.Retrived == false) { return(base.Dequeue()); } else { //if the tail value is retrived then move the tail pointer to the next older //If all the elements are retrived this will become a loop..so avoid by attempting only to the size of the array int attempts = this._length; //no of item in the buffer while (attempts > 0 && tail.Retrived == true) { //move to next oldest and check for the retrivel this.MoveTailToNextOldest(); tail = this.GetTail(); attempts--; } if (attempts == 0) { //It tried all the elements in the buffer but every element is retrived before throw new Exception("cannot add elements to the buffer"); } return(base.Dequeue()); } }
public CircularQueueItem <T> Get() { CircularQueueItem <T> tail = base.GetTail(); tail.Retrived = true; return(tail); }
public override void Enqueue(CircularQueueItem <T> toAdd) { //get the next index and check whehter it can be enqueued }
public bool CheckItemReadByIndex(int position) { CircularQueueItem <T> item = _buffer[position]; return(item.Retrived); }