Subj : Re: File Exporer like Sorting To : comp.programming,alt.comp.programming From : mensanator@aol.com Date : Sat Sep 24 2005 12:52 pm Newb wrote: > What is the best type of algorithm/strategy > to tackle a problem like this? > > I have data which is similiar to a files inside a > directory > > 1) Name 2) Size 3) Time 4) Someother Property > > Some of these are strings & some ints. > > The list of data is maintained in the order in which > I recieve it. I want to always remember this order > (i.e. get back this order if needed) Then add an index field to your record structure that stores a sequential record count. Sorting by this number will restore the table to it's original order. > > But at different times, I want this data sorted by > name or size or any of the other properties. As long as you can restore the original order, you are free to sort on any other field. > > What's the best way to accomplish this? Use a database program. > What strategy is best suited for different sample > sizes - i.e. if I expect to have 10 such elements > on the average or 100 such elements or 1000? If that's the range of data, a database may be overkill. Unless you already have a database program. I use MS-Access for even the most trivial uses because - I already own a copy - I don't have to worry about the data becoming impractically large at a later date - a database gives you a lot of ways to manipulate data in addition to sorting. But I wouldn't go out and buy MS-Access just to store a thousand or fewer records. I would simply write the data to a sequential text file and read the whole thing into a RAM array to use it. > > I am going to be programming this in Java. And if you did use a database, you could always use java to query an external database and do your own data manipulation. And MS-Access certainly isn't the only database available. > I am not interested in actual code - I am > just interested in what are the various > ways to achieve this. One other consideration is that a database application like MS-Access can do all the things you described (and more) without ever writing any code. On the minus side, I use Python to work with unlimited precision integers and sometimes I would like to store some results in MS-Access. But unlimited precision integers isn't a data type supported by MS-Access, so even though I have it, it's of no use to me for certain problems. Like many problems, much depends on how you're going to use the data, what tools you have, what tools you need to obtain and what the costs are in terms of money, time & effort. .