Doubly Linked List Problem

This is part of a larger project im working on for class and I don't need answers to it I just feel like im not quite grasping the proper way to implement a DLL efficiently as the code I have below will compile but provides no output.
So far the point of the code is to set up multiple DLL entries where each node carries 3 sets of data (polynomial expression) but I cant seem to get the program to even output a single list made up of multiple nodes, the next step for me will be to compare multiple lists which is why ill need to expand it to more lists i.e exp2.insertInOrder exp3.insertInOrder

Any nudges in the right direction would be great just cant for the life of me figure out why it will compile but not print my 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using namespace std;

struct Node {
	
	int data1;
	int data2;
	int data3;
	Node* next = NULL;
	Node* curr = NULL;
	Node* prev = NULL;

};

class PolyLL {
public:
	int data1, data2, data3;
	Node* insertInOrder(Node* head, int first, int second, int third) {
		Node* nn = new Node;
		nn->data1 = first;
		nn->data2 = second;
		nn->data3 = third;
		nn->next = NULL;
		nn->prev = NULL;

		Node* curr = head;
		if (curr == NULL) {
			head = nn;
			return head;
		}
		if (curr->data2 > nn->data2) {
			nn->next = curr;
			curr->prev = nn;
			head = nn;
			return head;
		}
		while (curr->next != NULL && curr->next->data2 < nn->data2) {
			curr = curr->next;
		}
		nn->next = curr->next;
		if (curr->next != NULL) 
			curr->next->prev = nn;
			curr->next = nn;
			nn->prev = curr;
			return head;
		}


	Node* print(Node* head)
		{
			Node* curr = head;
			while (curr != NULL)
			{
				cout << curr->data1 << ", " << curr->data2<<", " << curr->data3 << " ";
				curr = curr->next;
			}
			cout << endl;
			return head;
		}

private:
	Node*head;
};





	int main()
	{
		PolyLL exp1;
		Node* head = NULL;
		exp1.insertInOrder(head, 5, 4, 2);
		exp1.insertInOrder(head, 2, 2, 3);
		exp1.insertInOrder(head, -6, 3, 1);
		exp1.insertInOrder(head, -7, 1, 0);
		exp1.insertInOrder(head, 6, 0, 0);

		exp1.print(head);

		system("Pause");
		return 0;
	}
Why does a Node have a curr pointer? A node is just one node. If anything has a "current node," it's the list itself.

I see that a PolyLL has a head pointer. But then why do you pass a separate head pointer to the methods?

Topic archived. No new replies allowed.