Results 1 to 8 of 8

Thread: Represent data in a Tree

  1. #1

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Represent data in a Tree

    Hi,

    I have the following data in a two dimension array

    RaceX/cRaceCar.cpp
    RaceX/dsutil.cpp
    RaceX/
    RaceX/res/bmp_fullroadq11.bmp
    RaceX/res/gold_tophy.bmp

    It is a path of the files / directories.

    I want to represent it in a tree structure.

    RaceX
    |_______cRaceCar.cpp
    |_______dsutil.cpp
    |_______res
    ...............|_______bmp_fullroadq11.bmp
    ...............|_______gold_tophy.bmp

    Please help me with an algorithm...

    Currently I am using the following..

    1) Sorting the List
    2) Printing the list one by one after checking the no of '/'

    The Vector Sort doesnt behave as expected...

    Any Help is appreciated.

    Thanks,
    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Have you considered using a treeview?

  3. #3

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Hi,

    I Solved it..
    I used Vectors and then
    Wrote my own algorithm to sort..
    then I traversed through the vector and then wrote it in the form of a tree..


    Thank you,
    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    std::sort from <algorithm> would have sorted it for you.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Hi,

    I tried using sort. But it dint help.. I see there is some problem in that, hence I wrote a small subroutine for bubble sort..

    Thanks,
    Pradeep
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You likely have the wrong sorting predicate.
    What do you store the strings in?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Hi,

    I used the Class object in the Sort method and the operator > was overloaded to comparing strings..

    It was not the problem of the std..
    even when i used to sort it using pipe.. and sort.. it behaved the same...
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's weird.
    Can't test right now, but I'm sure this should work:
    Code:
    #include <string>
    #include <vector>
    #include <algorithm>
    using std::string;
    using std::vector;
    using std::sort;
    
    typedef vector<string> strvec;
    
    int main()
    {
      strvec strs;
      strs.push_back("kjla");
      strs.push_back("afa w");
      strs.push_back("sgcsf");
      strs.push_back("s3ss");
      strs.push_back("3ggxt");
      sort(strs.begin(), strs.end());
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width