Doubly Linked List

Hey, i have to write a doubly linked list of at least 5 elements and output the string data attribute for each link, and write an add method and a delete method and test both routines. I have a bit of code from class, but im not really sure where to take it or what to do.

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
 #include "stdafx.h"
#include <iostream>
using namespace std;

class Node {
public:
	Node*p;
	int data;
	void add(int input) {
		data = input;
	}
	};



	class LL {
	public:

		void add(int);
	};


	int main() {
		LL l;
		for (int j = 0; j < 5; j++) {
			l.add((j + 1));
		}
		return 0;
}

	void LL::add(int in) {
		Node *head = NULL;
		Node *cursor;
		Node *n = new Node();
		if (head == NULL) {
			head = n;
			cursor = head;
			cursor->p = NULL;
		}
		else {
			cursor->p = n;
			cursor = cursor->p;
			cursor->add(in);
		}


	}
Topic archived. No new replies allowed.