Reversing a Multi-D Array

This is a discussion on Reversing a Multi-D Array within the C++ Programming forums, part of the General Programming Boards category; I have an assignment in which I must be able to find all of the ancestors of a node in ...

  1. #1
    Bradley33
    Guest

    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)

    {return;}

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

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

    {

    //strcpy(key,curr->parent->value);

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

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

    ctr++;

    NextParent();

    }

    while (x < ctr)

    {

    strcpy(reverse[(x+ctr)],temp[(ctr-x)]);

    x++;

    }

    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?

    Thanks

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    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 (lightatdawn.cprogramming.com)

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, 02: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, 01:13 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. checking x size of multi 2-d array
    By aaronc in forum C Programming
    Replies: 1
    Last Post: 05-25-2004, 12:56 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

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