Str1ke
❔ I made a function to check that there is no Same last variable in two queues in the queue array
public static bool NoSameLast(Queue<int>[] arr)
{
Queue<int> queue = new Queue<int>();
for (int i = 0; i < arr.Length; i++)
{
int last= 2;
int secondlast= -2;
while (!arr[i].IsEmpty())
{
int x = arr[i].Remove();
queue.Insert(x);
last = x;
}
while (!queue.IsEmpty())
{
arr[i].Insert(queue.Remove());
}
for (int x = i+1; x < arr.Length;i++)
{
while (!arr[x].IsEmpty())
{
int y = arr[x].Remove();
queue.Insert(y);
secondlast = y;
}
while (!queue.IsEmpty())
{
arr[x].Insert(queue.Remove());
}
if (last == secondlast)
{
return false;
}
}
}
return true;
4 replies