c++ commenting

Can anyone help to explain this section of coding from a stack and queue program?
Such as adding some explained commenting for me to get a better understanding of what this code does.
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
template <typename T>
class Queue : protected Stack<T>
{
private:
	Node<T> *pFront;
public:
	Queue(void);
	~Queue(void);
	virtual void enqueue(T value);
	virtual Node<T>* nodeDequeue(void);
	virtual T dequeue(void);
};

template<typename T>
void Queue<T>::enqueue(T value)
{
	this->Push(value);

	if (pFront == nullptr) pFront = pTop;
	// 
	else (pTop->pNext)->pPrevious = pTop;
}
template<typename T>
Queue<T>::Queue(void)
{
	pFront = pTop = nullptr;
}
Last edited on
Don't you wish people who code just wrote the comments as they went ?
Ill take a crack at it, and assume you don't know much.

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
template <typename T>  //a template class is a generic design that allows you
//to insert any type.  It is useful for containers, of course, so you can have a 
//stack of int or double or your own class etc. 

class Queue : protected Stack<T>  //this class is the queue, it inherits from stack class (not seen). 
{
private:   //this is pointless, because class members are private by default. 
	Node<T> *pFront;  //the queue class has a private node.  Presumably a linked list type thingy, also not seen. 
public:   //the opposite of private, these variables and methods etc can be accessed by the user outside the class' internal functions. 

	Queue(void);    //these are function prototypes; this class with define these "methods" or functions that tightly couple the class' data with functions that operate on the data. 
//This one is the constructor, called when you create a variable of queue class type. 


	~Queue(void);  //~ is the class destructor,  called when a variable of the class type goes out of scope. 

	virtual void enqueue(T value);  //presumably adds an item to your queue. 
	virtual Node<T>* nodeDequeue(void); //presumably removes item from queue. 
	virtual T dequeue(void);  //a second way to remove from the queue somehow.  also, note that virtual functions can be (re)written by the class user, and may not even have a body until the user writes one.  It varies. Probably being overused here. 
};

template<typename T>    //function bodies. 
void Queue<T>::enqueue(T value)
{
	this->Push(value);  //call some unseen function push

	if (pFront == nullptr) pFront = pTop;  //handle case of null pointer
	// 
	else (pTop->pNext)->pPrevious = pTop; //handle normal case
}
template<typename T>
Queue<T>::Queue(void)  //body for constructor.  sets pointers to null. 
{
	pFront = pTop = nullptr;
}
Last edited on
Topic archived. No new replies allowed.