Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

106 lines (80 sloc) 1.499 kB
#ifndef RBX_LINKEDLIST_HPP
#define RBX_LINKEDLIST_HPP
#include <stdio.h>
#include <assert.h>
class LinkedList {
public:
class Node {
private:
Node* next_;
Node* prev_;
public:
Node();
Node* next() {
return next_;
}
Node* prev() {
return prev_;
}
void set_next(Node* n) {
next_ = n;
}
void set_prev(Node* n) {
prev_ = n;
}
void remove_linkage() {
if(next_) {
assert(next_->prev() == this);
next_->set_prev(prev_);
}
if(prev_) {
assert(prev_->next() == this);
prev_->set_next(next_);
}
next_ = NULL;
prev_ = NULL;
}
};
private:
Node* head_;
size_t count_;
public:
LinkedList();
Node* head() {
return head_;
}
size_t size() const;
void add(Node*);
void remove(Node*);
// Utility templates
template <typename Roots, typename Root>
class Iterator {
Roots& roots_;
Root* current_;
public:
Iterator(Roots& roots)
: roots_(roots)
, current_(roots.front())
{}
bool more() {
return current_ != 0;
}
void advance() {
current_ = static_cast<Root*>(current_->next());
}
Root* operator->() {
return current_;
}
Root* current() {
return current_;
}
Root* next() {
Root* ret = current_;
if(current_) {
current_ = static_cast<Root*>(current_->next());
}
return ret;
}
};
};
#endif
Jump to Line
Something went wrong with that request. Please try again.