|
-
Sep 26th, 2003, 01:33 AM
#1
Thread Starter
Fanatic Member
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
-
Sep 26th, 2003, 09:18 AM
#2
Frenzied Member
Have you considered using a treeview?
-
Sep 26th, 2003, 09:20 AM
#3
Thread Starter
Fanatic Member
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
-
Sep 29th, 2003, 01:24 AM
#4
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.
-
Sep 29th, 2003, 02:01 AM
#5
Thread Starter
Fanatic Member
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
-
Sep 29th, 2003, 04:44 AM
#6
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.
-
Sep 29th, 2003, 04:51 AM
#7
Thread Starter
Fanatic Member
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...
-
Sep 29th, 2003, 05:52 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|