Thread: Tree Initialisation

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    43

    Tree Initialisation

    Hi, if I have a tree of integers indexed by strings, like:

    Code:
    typedef struct TNode {
    char *s;
    int i;
    TNode *Left;
    TNode *Right; }
    then is there any quick way to intialise it (other than simply using the standard "add to tree" algorithm n times) if the entries (s, i) are known at Compile-Time? I thought probably not because there are pointers in there whose values would not be known until Run-Time...?

    Or is there some quicker way to index integers by strings?

    (NOTE: I am indexing INTEGERS by STRINGS, not the other way around, or I would just use an array).

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you could create an array containing your data, then have a program loop over that array, calling addToTree() for each one.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM