Мой код не отображает вывод. Это мой вопрос
Учитывая список, измените его так, чтобы все нечетные элементы отображались перед четными. Порядок нечетных и четных элементов должен оставаться неизменным.
Формат ввода Первая строка содержит целое число N, количество элементов в списке.
Следующая строка содержит N разделенных пробелами целых элементов списка
Пример ввода 5 1 2 3 4 5
Пример ввода 1 3 5 2 4
#include <iostream>
using namespace std;
class node
{
public:
int data;
node *next;
node (int d)
{
data = d;
next = NULL;
}
};
void insert(node *&head, node*&tail ,int data)
{
if (head == NULL)
{
head = tail = new node (data);
return ;
}
else
{
node* n = new node(data);
tail->next = n;
tail = n;
}
}
void seg(node *&head)
{
node *current = head;
node *estart = NULL;
node *Eend = NULL;
node *ostart = NULL;
node *oend = NULL;
while (current != NULL)
{
int value = current->data;
if (value % 2 == 0)
{
if (estart == NULL)
{
estart = Eend = current;
}
else
{
Eend->next = current;
current = Eend;
}
}
else
{
if (ostart == NULL)
{
ostart = oend = current;
}
else
{
oend->next = current;
current = oend;
}
}
current = current->next;
}
if (ostart != NULL)
{
head = ostart;
oend->next = estart;
Eend->next = NULL;
}
else
{
head = estart;
Eend->next = NULL;
}
}
void print(node *head)
{
while (head != NULL)
{
cout << head->data;
head = head->next;
}
cout << endl;
}
int main()
{
node *head = NULL, *tail = NULL;
int n;
cin >> n;
int m;
for (int i = 1; i <= n; i++)
{
cin >> m;
insert(head, tail, m);
}
seg(head);
print(head);
return 0;
}