Tree Initialisation

This is a discussion on Tree Initialisation within the C Programming forums, part of the General Programming Boards category; Hi, if I have a tree of integers indexed by strings, like: Code: typedef struct TNode { char *s; int ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08: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, 09:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

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