Yes. Now that will make your code more readable
Which is always a good thing.
Now, as for your question about the linked lists...? What was it again?
How to link the prev pointer to each node so all nodes are linked by an *next and *prev
I can implement *next fine, that's easy, but it doesn't work too well when I try to use the *prev pointer.
The prev pointer works pretty much like the next pointer, but points the other way around, so when you add something to a dlist, you link the prev-pointer of the new node to the previous node, and the next node of the previous node to the new node, for example.
The first nodes prev pointer is NULL [or whatever you use as a end-marker], and the last nodes next pointer is NULL.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Along the lines for a few scenarios of working with double-linked lists, here's a little source snippet from me to demonstrate how a linked list can work:
This was actual C++ code converted to C code, but I hope you may still find it relevant to understand how a double linked list works.Code:struct CLinkedListBeginOrEnd { CLinkedList* pBegin; CLinkedList* pEnd; }; CLinkedList* pPrevious; CLinkedList* pNext; CLinkedListBeginOrEnd* pBeginOrEnd; void InsertAfter(CLinkedList* pAdd, CLinkedList* pAfter) { CLinkedList* pNextNode = pAfter->pNext; CLinkedList* pPrevNode = pAfter; pPrevNode->pNext = pAdd; if (pNextNode) pNextNode->pPrevious = pAdd; pPrevious = pPrevNode; pNext = pNextNode; if (pNextNode == NULL) // We're the last node pBeginOrEnd->pEnd = this; }
Remember: Don't copy. Understand how the code works and you'll get the hang of how a double-linked list works. Then make your own.
Thanks Elysia and matsp, I will review it, the steps are what I need to review, I can code it easily after that. Thanks again !