Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LList *EnchantList = new LList; // Instantiate a Linked List object.
- /* Looping and Pushing the Roster names into the front of the linked list */
- for (RosterUnit *pRosterUnit = *(p_D2CLIENT_PlayerUnitList); pRosterUnit; pRosterUnit = pRosterUnit->pNext)
- {
- PrintText("%s", pRosterUnit->szName);
- EnchantList->push(pRosterUnit->szName);
- }
- /* Traverse the linked list and fetch the data from it while outputting it afterwards. How should i traverse the linked list properly because my WIP draft doesn't work :( */
- for(Node *EnchantItem = reinterpret_cast<Node *>(EnchantList->first()); EnchantItem != NULL; EnchantItem = reinterpret_cast<Node *>(EnchantList->next()))
- {
- PrintText("%s", EnchantItem->Data());
- }
- /* Class Header Below */
- // llist1.hpp
- // ctrudeau@etude
- //
- // This file contains the declaration for the link list class.
- //
- // ----------------------------------------------------------------------------
- #include <stdio.h>
- // Node - container where objects in the linked list are stored
- class Node
- {
- public:
- Node( void *_pData )
- {
- pData = _pData;
- pNext = NULL;
- } // end constructor
- Node *Next() { return( pNext ); }
- void SetNext( Node *pNode ) { pNext = pNode; }
- void *Data() { return( pData ); }
- private:
- void *pData;
- Node *pNext;
- }; // end Node
- // ----------------------------------------------------------------------------
- class LList
- {
- public:
- LList()
- {
- pHead = NULL;
- pTail = NULL;
- pCurrent = NULL;
- } // end constructor
- ~LList() { this->destroy(); }
- // member functions for manipulating the list
- void push( void *pData );
- void queue( void *pData );
- void *pop();
- void destroy();
- // member functions for traversing the list
- void top() { pCurrent = NULL; }
- void *first()
- {
- if( pHead == NULL )
- return( NULL );
- return( pHead->Data() );
- } // end first
- void *last()
- {
- if( pTail == NULL )
- return( NULL );
- return( pTail->Data() );
- } // end last
- void *next();
- private:
- Node *pHead;
- Node *pTail;
- Node *pCurrent;
- }; // end LList
- // ----------------------------------------------------------------------------
- /* Class Implementation (That i make use of) in the current code. */
- void *LList::next()
- {
- // if the list is empty return NULL
- if( pHead == NULL )
- return( NULL );
- // change the current pointer
- if( pCurrent == NULL )
- pCurrent = pHead;
- else
- pCurrent = pCurrent->Next();
- if( pCurrent == NULL )
- return( NULL );
- return( pCurrent->Data() );
- } // end next
- void *first()
- {
- if( pHead == NULL )
- return( NULL );
- return( pHead->Data() );
- } // end first
Add Comment
Please, Sign In to add comment