avishy
Queue and Node question
public static bool EqualSums(Queue<int> q)
{
int first = q.Remove();
int last = RemoveLast(q);
int sum = first + last;
Queue<int> c = q;
for(int i = 0; i < Length(q)/2; i++)
{
if(q.Remove() + RemoveLast(q) != sum)
{
return false;
}
}
if(!q.IsEmpty() && q.Remove() != sum) { return false; }
return true;
}
public static void RemoveEqualSums(Node<Queue<int>> lst)
{
Node<Queue<int>> curr = lst;
if (EqualSums(curr.GetValue()) == false)
{
curr.SetNext(null);
}
while (curr.GetNext() != null)
{
if(EqualSums(curr.GetNext().GetValue()) ==false)
{
curr.SetNext(curr.GetNext().GetNext());
curr.GetNext().SetNext(null);
}
curr = curr.GetNext();
} } why is this code incorrect? please help
} } why is this code incorrect? please help
2 replies