Thanks for all your responses. I see why c# is such a powerful language and
starting to like it more and more.
I also need help sorting this nested list. It is a little tricky. not sure
where to start.
I was thinking about creating a mapper for the nested lists.
List<stringstringList = new List<string>();
List<List<int>intLists = new List<List<int>>();
stringList.Add("c");
stringList.Add("b");
stringList.Add("a");
intLists.Add(new List<int>());
intLists.Add(new List<int>());
intLists.Add(new List<int>());
intLists[0].Add(3);
intLists[0].Add(1);
intLists[0].Add(2);
intLists[1].Add(7);
intLists[1].Add(8);
intLists[1].Add(2);
intLists[2].Add(0);
intLists[2].Add(9);
intLists[2].Add(9);
Output would be-
a,b,c
2,1,3
2,8,7
9,9,0
Any suggestions?
Tem 6 4842
On Sat, 03 May 2008 23:43:17 -0700, Tem <te*****@yahoo.comwrote:
[...]
I also need help sorting this nested list. It is a little tricky. not
sure where to start.
[...]
Any suggestions?
Yes. Stop making these parallel data structures. :)
Seriously though...
The approach I suggested earlier about having a separate integer list
that's used as an index is probably the most straight-forward approach,
barring fixing the data structure so it's not so clumsy. I wasn't aware
of the Array.Sort() overload Arne mentioned, and that seemed like the
perfect solution to your specific problem as stated earlier. But if you
have more than two correlated lists, that's not going to do it. A sorted
index list would, however.
Pete
Im not sure how to build such sorted index list.
SortedList<string, intlist = new SortedList<string, int>();
is this what you are referring?
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 03 May 2008 23:43:17 -0700, Tem <te*****@yahoo.comwrote:
>[...] I also need help sorting this nested list. It is a little tricky. not sure where to start. [...] Any suggestions?
Yes. Stop making these parallel data structures. :)
Seriously though...
The approach I suggested earlier about having a separate integer list
that's used as an index is probably the most straight-forward approach,
barring fixing the data structure so it's not so clumsy. I wasn't aware
of the Array.Sort() overload Arne mentioned, and that seemed like the
perfect solution to your specific problem as stated earlier. But if you
have more than two correlated lists, that's not going to do it. A sorted
index list would, however.
Pete
Tem wrote:
Thanks for all your responses. I see why c# is such a powerful language
and starting to like it more and more.
I also need help sorting this nested list. It is a little tricky. not
sure where to start.
I was thinking about creating a mapper for the nested lists.
List<stringstringList = new List<string>();
List<List<int>intLists = new List<List<int>>();
stringList.Add("c");
stringList.Add("b");
stringList.Add("a");
intLists.Add(new List<int>());
intLists.Add(new List<int>());
intLists.Add(new List<int>());
intLists[0].Add(3);
intLists[0].Add(1);
intLists[0].Add(2);
intLists[1].Add(7);
intLists[1].Add(8);
intLists[1].Add(2);
intLists[2].Add(0);
intLists[2].Add(9);
intLists[2].Add(9);
Output would be-
a,b,c
2,1,3
2,8,7
9,9,0
This basicly the same problem. You sort the string list and you
similar sort 3 int lists (intLists[0], intLists[1] and intLists[2]).
You can do it.
But you should seriously consider restructuring the data.
Arne
Do you have any suggestions on how I can better structure the data?
It needs to have a flexible list size where lists can be added or removed.
"Arne Vajhj" <ar**@vajhoej.dkwrote in message
news:48***********************@news.sunsite.dk...
Tem wrote:
>Thanks for all your responses. I see why c# is such a powerful language and starting to like it more and more.
I also need help sorting this nested list. It is a little tricky. not sure where to start. I was thinking about creating a mapper for the nested lists.
List<stringstringList = new List<string>(); List<List<int>intLists = new List<List<int>>();
stringList.Add("c"); stringList.Add("b"); stringList.Add("a");
intLists.Add(new List<int>()); intLists.Add(new List<int>()); intLists.Add(new List<int>());
intLists[0].Add(3); intLists[0].Add(1); intLists[0].Add(2);
intLists[1].Add(7); intLists[1].Add(8); intLists[1].Add(2);
intLists[2].Add(0); intLists[2].Add(9); intLists[2].Add(9);
Output would be- a,b,c 2,1,3 2,8,7 9,9,0
This basicly the same problem. You sort the string list and you
similar sort 3 int lists (intLists[0], intLists[1] and intLists[2]).
You can do it.
But you should seriously consider restructuring the data.
Arne
Tem wrote:
Do you have any suggestions on how I can better structure the data?
It needs to have a flexible list size where lists can be added or removed.
I think you need a class that contains a string and a List<int>.
Private fields and public properties ofcourse.
And implementing the IComparer<stringinterface that allows
for natural sorting.
Arne
On Sun, 04 May 2008 20:16:26 -0700, Tem <te*****@yahoo.comwrote:
Do you have any suggestions on how I can better structure the data?
It needs to have a flexible list size where lists can be added or
removed.
I don't really understand what you mean by "where lists can be added or
removed". That's too vague a statement to be meaningful.
However, looking at your most recent example, you could define a class
like this:
class A
{
string str;
List<intlistInts;
}
Where the field "str" contains the element that would have been in your
stringList, and the listInts list contains the respective elements that
would have been in each of your intLists at the appropriate position for
the string.
As Arne says, the actual class would be declared more appropriately, with
private fields, public properties, etc.
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Xah Lee |
last post by:
Sort a List
Xah Lee, 200510
In this page, we show how to sort a list in Python & Perl and also
discuss some math of sort.
To sort a list in Python, use the “sort” method. For example:
...
|
by: DancnDude |
last post by:
I have a class that needs to have several different kinds of sorting
routines on an ArrayList that it needs to conditionally do based upon the
data. I have successfully created a class that...
|
by: Kent |
last post by:
Hi!
I want to store data (of enemys in a game) as a linked list, each node will
look something like the following:
struct node
{
double x,y; // x and y position coordinates
struct enemy...
|
by: Ed Sutton |
last post by:
I need to do a custom sort on a TreeView. I have various object types
associated with the TreeNode Tag property. I want to sort objects of
the same type at the top of the list, other objects at...
|
by: joseph speigle |
last post by:
hi,
To see the query results in native language see
http://database.sarang.net/?inc=read&aid=5368&criteria=pgsql&subcrit=qna&id=&limit=20&keyword=&page=1
the simpler url is
...
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: AB |
last post by:
Hello All,
I'm trying to replicate a general purpose sort function (think qsort)
void sort(void *arr, const int num, size_t size,
int (*cmp)(void *a, void *b))
{
int i = 0 ;
int j = 0 ;
|
by: xahlee |
last post by:
Last year, i've posted a tutorial and commentary about Python and
Perl's sort function. (http://xahlee.org/perl-python/sort_list.html)
In that article, i discussed a technique known among...
|
by: Marc Gravell |
last post by:
To illustrate Peter's point - here is the code (using C# 3 for
brevity, but only .NET 2.0 - no LINQ etc) to do this using an entity
(SomeType) to represent the combined values:
Marc
using...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |