これまでのところ、このすべては(少なくとも私が笑そう願って)ないだから私は(まず第一に出て)通常のキューの思考を遵守、私の質問が何であるかキュークラス/のisEmptyメソッド
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;
}
}
を推測する方法私はそれを停止するのですか?私は、範囲外のエラーのインデックスを取得し続けます。
140列の行はあまり読み込めません。それを分解してください。 –
これはどのように読めないのですか?私は行などをスキップしました。 – Nogg
これはクローズではありません、これはキューよりもスタックのようです。必要なヘルプを得るには、[宿題]タグを使用する必要があります。 –