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

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;
}
6 Replies
ora
ora16mo ago
It's hard to understand what you're asking for. But essentially: In: 1,2,3,4,5,6 Out:2,4,6,1,3,5 Correct?
חגית שמעוני
yes sorry my english isnt the best
ora
ora16mo ago
I'm hesitant to write actual code because this looks like a CS assignment
חגית שמעוני
what do you mean?
ora
ora16mo ago
It looks like the type of thing you'd be asked to write for school.
חגית שמעוני
its an online course i dont need to send it i just dont understand its videos then it has questions about the videos

Did you find this page helpful?