The way I created my generic, Linked List, class was w/an inner defined structure (chosen simply because it's public by default) that the outer class would instantiate an instance of and, therefore, keep it self contained without having to rely on a static implimentation - which would limit it to only one instance of the outer class per project:
class:
Here's my implementation to remove any given link from doubly linked list:Code:class Linker { struct BiDirectional { BiDirectional* next; BiDirectional* prev; void* pData; BiDirectional(); ~BiDirectional(); }; unsigned int counter; BiDirectional* head; BiDirectional* tail; public: Linker(); ~Linker(); void AddLink(void*); void* RetrieveLink(unsigned int); void* RetrieveLink(void*); void* RemoveLink(unsigned int); void* RemoveLink(void*); unsigned int Size(); };
I hope that's of any help.Code:void* Linker::RemoveLink(unsigned int index) { BiDirectional* temp = head; for ( unsigned int i = 0; i < counter; ++i, temp = temp->next ) { if ( i == index ) { // checks against first link if ( temp == head ) { if ( temp->next != NULL ) { temp->next->prev = NULL; head = temp->next; void* pData = temp->pData; delete temp; counter--; return pData; } else { head = tail = NULL; void* pData = temp->pData; delete temp; counter--; return pData; } } // checks against last link else if ( temp == tail ) { temp->prev->next = NULL; tail = temp->prev; void* pData = temp->pData; delete temp; counter--; return pData; } // checks against middle links else { temp->prev->next = temp->next; temp->next->prev = temp->prev; void* pData = temp->pData; delete temp; counter--; return pData; } } } // no match return NULL; }



LinkBack URL
About LinkBacks



. Given your exercise, how would I go about reversing the order with only being able to move the top book? I can think of a couple of ways but, I don't think they're right... I need more hints.