need help with linklist

lets say i have 1 linklist with diffrent numbers
how can i make 2 lists from 1 single list
1 list to odd numbers
and the second one from even numbers.
tnx for helpers appricate have a great day guys
One way to do it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
list<int> allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  list<int> evenNumbers, oddNumbers;

  for (int i : allNumbers)
  {
    if (i % 2 == 0) // even
    {
      evenNumbers.push_back (i);
    }
    else // odd number
    {
      oddNumbers.push_back (i);
    }
  }
Another way would be to simply take all the odd elements from the original list (erasing them from the list) and put them into a new list. This leaves you with the original list containing even numbers and the new list creating odd numbers.

Of course, if you want to keep the original list as it is, this may not be the preferred solution.
tnx for help ..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void List::fix(const int & num){
	Node* now = new Node(num);
	//empty
	if (head == NULL){
		head = now;
	}
	else{
		Node *first = head;
		Node * some = 0;
		while (first != NULL){
			if (first->num>= now->num){
				break;

			}
			else{
				some = first;
				first = first->next;
			}
		}
		if (first == head){
			now->next = head;
			head = now;
		}
		else{
			now->next = first;
			some->next = now;
		}
	}
	size++;
}


like this code that i made the list from small to big..
so how can i split 1 linklist to two diffrent linklist
Topic archived. No new replies allowed.