-
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
-
Have you considered using a treeview?
-
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
-
std::sort from <algorithm> would have sorted it for you.
-
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
-
You likely have the wrong sorting predicate.
What do you store the strings in?
-
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...
-
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());
}