Doubly Linked List problem

Is it the right way to insert element(s) in Doubly Linked List?

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
47
48
49
50
51
52
53
#include <iostream>
using namespace std;

class node{
	public:
		int value;
		node *prev;
		node *next;
	
		void insert(node *&, node *&, int);
};

void insert(node *&head, node *&tail, int x)
{
	node *temp = new node;
	temp->value  = x;
	temp->prev = NULL;
	temp->next = NULL;

	if(head == NULL && tail == NULL){
		head = temp;
		tail = temp;
	}

	else{
		temp->next = head;
		head = temp;
	}
}

int main()
{
	node *head = NULL;
	node *tail = NULL;

	int n;

	for(int n=0; n<10; n++){
		//cout<<"Enter the value: ";
		//cin>>n;

		insert(head, tail, n);
	}

	cout<<"NULL <- ";
	for(node *p=head; p!=NULL; p=p->next)
		cout<<p->value<<" <--> ";
		cout<<"NULL";

	cout<<endl;
	system ("Pause");
	return 0;
}
It looks ok to me.
Ya its fine. But where my confusion is; else part looks like singly lined list insertion. Is that part too easy like that??
Topic archived. No new replies allowed.