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<stringstri ngList = new List<string>();
List<List<int>i ntLists = new List<List<int>> ();
stringList.Add( "c");
stringList.Add( "b");
stringList.Add( "a");
intLists.Add(ne w List<int>());
intLists.Add(ne w List<int>());
intLists.Add(ne w 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 4857
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<stri ng, intlist = new SortedList<stri ng, int>();
is this what you are referring?
"Peter Duniho" <Np*********@nn owslpianmk.comw rote 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<stringstri ngList = new List<string>();
List<List<int>i ntLists = new List<List<int>> ();
stringList.Add( "c");
stringList.Add( "b");
stringList.Add( "a");
intLists.Add(ne w List<int>());
intLists.Add(ne w List<int>());
intLists.Add(ne w 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.d kwrote in message
news:48******** *************** @news.sunsite.d k...
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<stringstri ngList = new List<string>(); List<List<int>i ntLists = new List<List<int>> ();
stringList.Add( "c"); stringList.Add( "b"); stringList.Add( "a");
intLists.Add(ne w List<int>()); intLists.Add(ne w List<int>()); intLists.Add(ne w 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<strin ginterface 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<intlistInt s;
}
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:
li=;
|
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 implements IComparer and
does the sort correctly for one of these sort types. This class's
definition is like:
// Sort class that implements IComparer so
public class CompareFields1 : IComparer
{
public int Compare(object a, object b)
|
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 *enemydata; // Holds information about an enemy (in a game)
// Its a double linked list node
|
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 the bottom. I
found some scraps of code in various postings that I am trying to get to
work.
I can not seem to get any meaningful data back from the CompareFunc
callback. According to MSDN, The lParam1 and lParam2 parameters
correspond to the...
|
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
http://database.sarang.net/?criteria=pgsql
becase there is no korean postgresql list. poster is "joesp"
| |
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 column. Once the
array elements are split, what is the best way to sort them? Thank you.
//populate data object with data from xml file.
//Data is a comma delimited list of values
var jsData = new Array();
jsData = {lib: "#field...
|
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 juvenile Perlers
as the Schwartzian Transform, which also manifests in Python as its
“key” optional parameter.
Here, i give a more detailed account on why and how of this construct.
----
|
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 System;
using System.Collections.Generic;
sealed class SomeType
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |