data structure question.. oohh how cool
this is the basic structure of a doubly linked list, which is most common.
I am writing all this right now, so there might be errors, but you should get the jist of it.
Code:
template<class T>class list{
public:
struct node{
node* prev, next;
T objectbeingheld;
};
node*curr;
list(): curr(NULL) {}
insert(T& object){// inserts before *this
if(curr==NULL){// this is the head node
objectbeinghelp = object;// you can use pointers of what ever you want
} // otherwise there is something in front of *this
node* temp = new node;
temp->prev = this->curr->prev;
temp->next = this;
temp->objectbeingheld=object;
prev = temp;
}// end of insert
remove(){// remove this node!!!
if(prev == NULL){// we are the head node.. ohh crap!
if(next==NULL){// we are empty what the hell !!
return;
}// there is a node behind us.. yay, we are loved!
next->prev = NULL;// make sure the next node KNOWS it is the head..
};
sorry I started getting tired and decided that I didn't want to write the code. Maybe you can decipher it, eh? I forgot that I needed to create a container to hold the nodes...
the term node is what is typically called each object held in a linked list. So, create a container to hold those nodes. Allocate new ones on an insert call, and call delete on a removal. I am going to sleep now