C
C#8mo ago
avishy

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
ora8mo 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?
avishy
avishy8mo ago
yes sorry my english isnt the best
ora
ora8mo ago
I'm hesitant to write actual code because this looks like a CS assignment
avishy
avishy8mo ago
what do you mean?
ora
ora8mo ago
It looks like the type of thing you'd be asked to write for school.
avishy
avishy8mo ago
its an online course i dont need to send it i just dont understand its videos then it has questions about the videos