linked list

Hi!
I'am trying to make my own function which creates linked list. I've already managed to do this function which creates the list from back to start, but now I would like to do it the other way, from start to the end. I have this piece of code:
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

struct node {
	int info;
	node* next;
};

node* start = NULL;
node* end = NULL;

void list_create(int N, node*& P, node*& Q)
{ // P will point on the first node and Q on the last one
	node* R;
	P = new node;
	P->info = 1;
	P->next = NULL;
	Q=P;
	for (int i=2; i!=N; ++i) {
		R = new node;
		R->info = i;
		Q->next = R;
		Q=R;
	}
	Q->next = NULL;
}

int main()
{
	cout << "Set the size: " << endl;
	int size;
	cin >> size;

	list_create(size, start, end);

	while (start != end) {
		cout << start->info << endl;
		start=start->next;
	}

	return 0;
}

The problem is, that the output looks like this:
Set the size:
5
1
2
3

By the way it's supposed to write it's values from start to end. And for simplicity I am making it just a list of integers...
Do you have a clue what the problem might be?

Thanks :)
Oh, am I an idiot?
Well, the problems are my silly condition in the loops!

So this is how it should be:
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

struct node {
	int info;
	node* next;
};

node* start = NULL;
node* end = NULL;

void list_create(int N, node*& P, node*& Q)
{ // P bude ukazovat na zaciatok zoznamu a Q na koniec
	node* R;
	P = new node;
	P->info = 1;
	P->next = NULL;
	Q=P;
	for (int i=2; i<=N; ++i) {
		R = new node;
		R->info = i;
		Q->next = R;
		Q=R;
	}
	Q->next = NULL;
}

int main()
{
	cout << "Set the size: " << endl;
	int size;
	cin >> size;

	list_create(size, start, end);

	
	for (int i=0; i != size; ++i) {
		cout << start->info << endl;
		start=start->next;
	}

	return 0;
}


Thx for help anyway :D.
Topic archived. No new replies allowed.