C
C#13mo ago
avishy

trying to create a function that returns the list from even numbers to odd numbers

public static Node<int> EvenOdd(Node<int> head)
{
Node<int> curr = head;
Node<int> newNode = new Node<int>(GetLength(head));


while (curr != null)
{
if (curr.GetValue() % 2 == 0)
{
if (newNode == null)
{
newNode = curr;
}
else { newNode.SetNext(curr) ; }
}
curr = curr.GetNext();
}
Node<int> curre = head;
while (curre != null)
{
if (curre.GetValue() % 2 != 0)
{
newNode.SetNext(curre);
}
curre = curre.GetNext();
}

return newNode;
}
public static Node<int> EvenOdd(Node<int> head)
{
Node<int> curr = head;
Node<int> newNode = new Node<int>(GetLength(head));


while (curr != null)
{
if (curr.GetValue() % 2 == 0)
{
if (newNode == null)
{
newNode = curr;
}
else { newNode.SetNext(curr) ; }
}
curr = curr.GetNext();
}
Node<int> curre = head;
while (curre != null)
{
if (curre.GetValue() % 2 != 0)
{
newNode.SetNext(curre);
}
curre = curre.GetNext();
}

return newNode;
}
1 Reply
Omnissiah
Omnissiah13mo ago
so this returns first all the even numbers and then all the odds?
Want results from more Discord servers?
Add your server