Thread: Reversing a Multi-D Array

  1. #1

    Reversing a Multi-D Array

    I have an assignment in which I must be able to find all of the ancestors of a node in a general tree and be able to print those ancestors in order from the root down:

    the nodes have values that are strings.

    I'm having a tough time getting my head around this. All of been able to come up w/ so far is using a multi-dimensional array, finding the values from the node up to the root, storing them in the array and then reversing it.

    Not having much luck though. Here's the code I have so far.

    // Finds All Of A Node's Ancestors

    void tree::FindAncestor(link *findtemp, char key[20])


    cout << endl;

    int foundFlag = 0;

    int ctr = 0;

    int x = 0;

    char temp[500][20];

    char reverse[500][20];

    Find(findtemp,key,foundFlag ); // Finds value for which ancestors must be found

    if (curr == root)


    cout << curr->value << "'s ancestors are: " << endl;

    while (curr->parent->value != NULL)



    strcpy(temp[ctr],curr->parent->value); //input value into array to be reversed later

    cout << temp[ctr] << " ";




    while (x < ctr)





    cout << endl << endl << temp;

    cout << endl << endl << reverse;


    I have some class specific stuff in there, but you should be able to follow it.

    When I print out the stuff at the end I get Hex addresses. Can anyone help? Or maybe tell me a better way of doing this?


  2. #2
    I didnt check over your code but from hearing you mention the Hex address thing, it would sound like your printing the address of the node instead of the actual values. You must be printing the pointer to the node.
    "There's always another way"
    -lightatdawn (

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help printing a multi array
    By cjohnman in forum C Programming
    Replies: 4
    Last Post: 05-05-2008, 01:35 PM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. checking x size of multi 2-d array
    By aaronc in forum C Programming
    Replies: 1
    Last Post: 05-24-2004, 11:56 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM