View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

#1Mr_Black  Members

Posted 19 November 1999 - 04:15 AM

Ok I know this is a basic subject, but I can remember for the life of me how to do them. Does anyone know how to do them or could you point me to an article on them.

#2MikeD  Members

Posted 19 November 1999 - 01:22 AM

Ah, Hell, I've got a spare ten minutes while my code compiles.
Okay, basic structure for a linked list

typedef struct
{
int i;
myStruct *next; // Pointer to the next node in the linked list
myStruct *previous; // Pointer to the previous node in the linked list
}myStruct;

myStruct *tail; // Pointer to the tail of the linked list

void
{
myStruct *newNode = new myStruct; // Generate a new node dynamically
if(!head) // If there is no current list
{
head = tail = newNode; // The head and tail of the list now point at the new node
head->previous = NULL; // Which points at nothing
}
else
{
tail->next = newNode; // The tail now points on to the new node
newNode->previous = tail; // Which points back to the tail
newNode->next = NULL; // And on to nothing
tail = newNode; // The tail is advanced to the last node
}
}

Removing a node involves setting up the next and previous pointers of the nodes (if they exist) before and after the node to be deleted then deleting the node with the delete function

Does that help?

#3Mr_Black  Members

Posted 19 November 1999 - 02:01 AM

Thanks a lot much appreciated

#4Zer  Members

Posted 19 November 1999 - 04:15 AM

Here's an easier way to do it.

#include "list"
using namespace std;

And from there, to add a mystruct to the end,

The front,