-
Linked Lists...
Ok, well i have never needed them before and i have done some googling and reading in my C++ book but i dont understand how to implement them. I understand what they are but am still a little confused. After writing this im gonna keep looking, dont get the idea that im being lazy im just confused.
Ok so here is my situation: im making a Tic Tac Toe program, i have been informed that i need to use a minimax tree for the programs AI. I feel that i have a good understanding of minimax trees and now if i understand correctly the only way to implement a minimax tree is through linked lists. I also dont believe there is a standard Linked List definition like there is a standard String or char array one. So if i am interpreting correctly i need to make a class for one. One is provided in my book but i need to know if there is anything that is: A. Simpler or B. Better for my specific need.
I have all of the program ready to go except for the AI so any help you guys can provide would be greatly appreciated! Thanks!
-
close....you need to make a structure
Code:
typedef struct node
{
NODE * left;
NODE * right;
//whatever other data that should be in each node in here
} NODE
So now all you have to do is create a new instance of this struct every time you want to ad one to the tree as your organizaing data
eg.
Code:
NODE *node = new NODE //(or malloc if you Prefer)
//put proper data in this node
tree.left = node; //where tree is jsut of type NODE where you currently are while building your tree
hope that helps
-
Thanks ill try it out tommorrow and see if i can get it to work for me. I appreciate your help!
-
The Standard Template Library does have a list class like it has a string class, a vector class, etc.
To me, trees and lists are closely related in the sense both are made up of nodes that are interconnected. The node has some data and the address of one or more other nodes. In a sense a list can be considered a tree where a given node points to only one other node (or maybe two if the given node can also point to the node that points to it). The first node of a list is often called the head instead of the root, as in a tree. A list typically has only a single terminal node, frequently called the tail node, as opposed to the multiple terminal nodes, frequently called leaves, in a typical tree. A list can be circular, but I've never seen a circular tree, though that doesn't mean much.