Linked Lists...

This is a discussion on Linked Lists... within the C++ Programming forums, part of the General Programming Boards category; Ok, well i have never needed them before and i have done some googling and reading in my C++ book ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Question 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!

  2. #2
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    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

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Thanks ill try it out tommorrow and see if i can get it to work for me. I appreciate your help!

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 05:30 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 05:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 09:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 07:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21