Пока все это делает (по крайней мере, я надеюсь, что так),
class Queue
{
private int front = 0; //Creates front and back int holders and an array
private int back = -1;
private int[] anArray;
public Queue(int size) // constructor to get the Queue size
{
anArray = new int[size];
}
public bool IsFull
{
get // gets to see if the Queue is full ( I assume I did this right, It's full if the back of the queue is equal to -1 of an array)
{
return back == anArray.Length - 1;
}
}
public bool IsEmpty
{
get // It's empty if the back is -1; I think this is where I messed up, I think that when it checks to see if it's empty it also doesn't check if it's empty when I have dequeued the other numbers (or write them off). Would I make something like "Return front == anArray.Length -1;" ? That would check to see when the front (The part being written to console first) hits the end of the array?
{
return back == -1;
}
}
public void Enqueue(int valueEnqueue)
{ // Method to Enqueue the variables into the array
if (IsFull)
{
//do nothing
}
else
{
back = back + 1;
anArray[back] = valueEnqueue;
}
}
public int Dequeue()
{ // Method to dequeue the variables put in
if (IsEmpty)
{
//do nothing
return 1010101010;
}
else
{
int dequeue = anArray[front];
front = front + 1;
return dequeue;
}
}
Итак, я догадываюсь, в чем заключается мой вопрос, придерживаясь нормального мышления в очереди (сначала в очередь первым), как мне заставить его остановиться? Я продолжаю получать индекс из-за ошибки диапазона.