News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

Data Structures using C++ assistance please.

Farted by Flask, March 19, 2011, 11:15:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Flask

I learned a while back how to make linked lists etc in C++. Now I'm getting back into it, and I can't seem to remember how to do it. I was using structs before, one for the entire node, and one for the data payload, with a named typedef of that payload type nested inside the node. I cant' for the life of me though seem to remember the most important part: storing the address of that node and the next node in the struct. Also, would a class be better for this, with virtual functions etc should I say want to make this into stacks, queues, binary trees etc? I can post code if requested, but it will take a bit to dig it up.
Quote from: BONGO BONGO;1009033please take some time to study this example of how you shouldn\'t act

Quote from: Masquatto;1009058With correct grammar and without predisposed antagonism?

Are you trying to look asinine?

Loki Clock

Pointers * are used to store the addresses, addresses & are used to get them. If you want to learn some OO approach to a linked list you're welcome, but it's a total overcomplication. If you want stacks, queues, etc., use STL.

SherClockHolmes

To carry on what Loki said each pointer is an edge to the next node.

For example I would probably set up something like so,

class Node {
public:
   Node();
   Node(Node* n);
   void setNode(Node *n);
   Node* getNode();
private:
   Node* n;
};

In the .cpp file you would have n equal the next pointer to the node you want in your list. The class can always be modified for the data you want to store. Does that help answer your question?

Flask

Quote from: SherClockHolmes;1812558To carry on what Loki said each pointer is an edge to the next node.

For example I would probably set up something like so,

class Node {
public:
   Node();
   Node(Node* n);
   void setNode(Node *n);
   Node* getNode();
private:
   Node* n;
};

In the .cpp file you would have n equal the next pointer to the node you want in your list. The class can always be modified for the data you want to store. Does that help answer your question?

Yes Thank you very much! Also, about STL, I do have a question about it, I heard it can slow down a program to an incredible degree, because using one container loads the whole STL. If it doesn't really slow down a program too much, then I fully agree. I've just been really... stuck lately on it. It's frustrating really. Thanks for your responses.
Quote from: BONGO BONGO;1009033please take some time to study this example of how you shouldn\'t act

Quote from: Masquatto;1009058With correct grammar and without predisposed antagonism?

Are you trying to look asinine?

Loki Clock

Quote from: Flask;1812638Yes Thank you very much! Also, about STL, I do have a question about it, I heard it can slow down a program to an incredible degree, because using one container loads the whole STL. If it doesn't really slow down a program too much, then I fully agree. I've just been really... stuck lately on it. It's frustrating really. Thanks for your responses.

If you don't already know what template specialization is, then find out before reading.
http://yosefk.com/c++fqa/templates.html#fqa-35.10

Then there's this:
http://www.gamedev.net/topic/191915-stl-too-slow-for-games/

Honestly, you should make the linked list regardless of STL's speed, because that's something you should have a firm grasp on the construction of.