473,714 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused by sorted list of a sorted list

J L
I want to create a sorted list whose values are themselves sorted
lists. I wrote the following simple test program but it does not
behave as I would expect.

What I wanted to do was have the doorConflictLis t be keyed on a door
ID and contain a sorted list called conFlictList. I wrote this
expecting the following

doorConflictLis t should end up with 3 items.
Item 1 would be a sorted list with 1 item
Item 2 would be a sorted list with 2 items
Item 3 would be a sorted list with 3 items.

I expected to see :

Door 0
Value 0
Door 1
Value 0
Value 1
Door 2
Value 0
Value 1
Value 2

but instead I see:

Door 0
Value 0
Value 1
Value 2
Door 1
Value 0
Value 1
Value 2
Door 2
Value 0
Value 1
Value 2

What am I doing wrong?

Here is the code :

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim conFlictList As New SortedList
Dim doorConflictLis t As New SortedList
Dim i As Integer
Dim m As Integer
Dim door As Integer
Dim numberOfDoors As Integer = 3
For door = 0 To numberOfDoors - 1
conFlictList.Cl ear()
For i = 0 To door
conFlictList.Ad d("Key " & i.ToString, "Value " &
i.ToString)
Next
doorConflictLis t.Add("Door " & door.ToString, conFlictList)
Next
Dim strMessage As String = ""
If doorConflictLis t.Count > 0 Then
For i = 0 To doorConflictLis t.Count - 1
strMessage += doorConflictLis t.GetKey(i) & vbCrLf
Dim theConflicts As SortedList = _
CType(doorConfl ictList.GetByIn dex(i), SortedList)
If theConflicts.Co unt > 0 Then
For m = 0 To theConflicts.Co unt - 1
strMessage += " " & theConflicts.Ge tByIndex(m) &
vbCrLf
Next
End If
Next
End If
MessageBox.Show (strMessage)
End Sub

TIA
John
Nov 21 '05 #1
1 1639
J L
Opps...embarras ing...I see it now...scope issue...
Needed to move the
Dim conflictlist as New SortedList
into the loop creating it, else I was pointing to the same sorted
list every time and hence the last one filled had the 3 values...well
that was not well stated but I see the problem...

John
On Sat, 25 Jun 2005 16:21:02 -0700, J L <jo**@marymonte .com> wrote:
I want to create a sorted list whose values are themselves sorted
lists. I wrote the following simple test program but it does not
behave as I would expect.

What I wanted to do was have the doorConflictLis t be keyed on a door
ID and contain a sorted list called conFlictList. I wrote this
expecting the following

doorConflictLi st should end up with 3 items.
Item 1 would be a sorted list with 1 item
Item 2 would be a sorted list with 2 items
Item 3 would be a sorted list with 3 items.

I expected to see :

Door 0
Value 0
Door 1
Value 0
Value 1
Door 2
Value 0
Value 1
Value 2

but instead I see:

Door 0
Value 0
Value 1
Value 2
Door 1
Value 0
Value 1
Value 2
Door 2
Value 0
Value 1
Value 2

What am I doing wrong?

Here is the code :

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim conFlictList As New SortedList
Dim doorConflictLis t As New SortedList
Dim i As Integer
Dim m As Integer
Dim door As Integer
Dim numberOfDoors As Integer = 3
For door = 0 To numberOfDoors - 1
conFlictList.Cl ear()
For i = 0 To door
conFlictList.Ad d("Key " & i.ToString, "Value " &
i.ToString)
Next
doorConflictLis t.Add("Door " & door.ToString, conFlictList)
Next
Dim strMessage As String = ""
If doorConflictLis t.Count > 0 Then
For i = 0 To doorConflictLis t.Count - 1
strMessage += doorConflictLis t.GetKey(i) & vbCrLf
Dim theConflicts As SortedList = _
CType(doorConfl ictList.GetByIn dex(i), SortedList)
If theConflicts.Co unt > 0 Then
For m = 0 To theConflicts.Co unt - 1
strMessage += " " & theConflicts.Ge tByIndex(m) &
vbCrLf
Next
End If
Next
End If
MessageBox.Show (strMessage)
End Sub

TIA
John


Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1519
by: Amy G | last post by:
I have a list of numbers... actully I have two lists, List 1 is a list of number strings and List2 is one of numbers. List 1 example: List1 = List 2 example: List2 = When I try either:
0
1581
by: Daniele Varrazzo | last post by:
If you need a container to look into, there is the sets module that provides a couple of them. If you need a sorted list, there is the bisect module. But i don't think it fits your need for a quick lookup: it's a python module so probably it's slower. Furthermore you can __hash__ almost everything, but you can __cmp__ in a consistent way much less stuff. Take definitely a look at sets.
57
3600
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
5
52114
by: MackS | last post by:
Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user sorted according to a certain criterion. Is there any direct way to do so? Or must I list = for item in set1:
10
15128
by: Der Andere | last post by:
I need to implement a sorted (ordered) list. STL has no sorted list type as far as I know. Is there a (straight) way to implement a sorted list using STL? BTW: The type of items in the list will be a class. Is it necessary to implement the > or < operators or to write a compare-function that returns the larger or smaller of two classes? Ideally, the list begins with the smallest element. Cheers, Matthias
3
22072
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** it's been a while since i have poseted to this newsgroup, but for a long time i was not programming at all. but now that i am out of college and facing the prospect of getting a real job, i need to get back into the game. anyway, i don't know if some of you know the stanford CS library. i took the problem set a while back and have recently rediscovered it adn have been trying...
4
1852
by: shrishjain | last post by:
Hi All, I need a type where I can store my items in sorted order. And I want to keep adding items to it, and want it to remain sorted. Is there any type in .net which I can make use of. I see there is SortedList<key, value> for hash tables, but could find anything for a sorted list. Currently I am using List<string> and whenever I add an item, I need to
1
1588
by: Khayrat | last post by:
Hi folks, please help I have a xml file with a list of items. The list is sorted during xslt processing. Based on this sorted list I want a navigation facility to walk through the sorted list starting from a choosen item via <back> and <next>. Say this is the list: <a>
8
2591
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array; m_ResultArray.Add ( aFoundObject);
0
8808
marktang
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9177
jinu1996
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...
0
7954
agi2029
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 project—planning, coding, testing, and deployment—without 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...
0
5951
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();...
0
4465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4727
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3159
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
2
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.