I am supposed to implement a Circular Doubly Linked list with header node in C++.
My professor gave me this algorithm but i can't understand the use of it.
Where and how should i use precede and follow and out?
Inside precede there is a 'P' which i dont understand where it came from, same goes for r in the follow method, and p and r in out method but i figured those might be just a new E2* so i created this
class E2 {
public:
E2* prev;
E2* next;
int key;
E2() {
prev = this;
next = this;
};
};
void precede(E2* q, E2* r) {
//insert (*q) before (*r)
E2* p = new E2();
p = r->prev;
q->prev = p;
q->next = r;
p->next = r->prev = q;
}
void follow(E2* p, E2* q) {
E2* r = new E2();
r = p->next;
q->prev = p;
q->next = r;
p->next = r->prev = q;
}
void out(E2* q) {
E2* r = new E2();
E2* p = new E2();
p = q->prev;
r = q->next;
p->next = r;
r->prev = p;
q->prev = q->next = this;
}
In the out method, the 'this' gives me an error which says: 'this' may only be used inside a nonstatic member function

E2* p = new E2(); p = r->prev;here you lose pointer to just allocated node. - faspis just a temp variable, (not a node that is allocated), and is assigned as shown in the function descriptions. - rcgldr