can you guys walk me through what this code is doing

I know this is a class that is defining a list data type.

the part that confuses me alot is this part

const list& operator=(const list& aList);

and also the this. Is the whole purpose of the struct node is to hold the data but also have another node point to the next or previous node? What about the int size? is that just stating the size of the data its holding?

1
2
3
4
5
6
7
8
9
	struct node
	{
		data item;
		node * next;
	};

	node*	head;
	int		size;
};


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
#ifndef LIST_H
#define LIST_H

#include <ostream>
#include "data.h"

class list
{
public:
	list(); // constructor
	list(const list& aList); // copy constructor
	~list(); // destructor

	const list& operator=(const list& aList);

	bool insert(const data& aData);
	bool remove(char* key);
	bool retrieve(char* key, data& aData) const;
	int getSize(void) const;

	friend ostream& operator<<(ostream& out, const list& lst);

private:
	struct node
	{
		data item;
		node * next;
	};

	node*	head;
	int		size;
};

#endif 
The class overloads operator=. See operator overloading.

and also the this. Is the whole purpose of the struct node is to hold the data but also have another node point to the next or previous node?

Yes, the next node.

What about the int size?

It's for keeping track of the number of elements in the list.
Topic archived. No new replies allowed.