473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 doorConflictList be keyed on a door
ID and contain a sorted list called conFlictList. I wrote this
expecting the following

doorConflictList 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conFlictList As New SortedList
Dim doorConflictList 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.Clear()
For i = 0 To door
conFlictList.Add("Key " & i.ToString, "Value " &
i.ToString)
Next
doorConflictList.Add("Door " & door.ToString, conFlictList)
Next
Dim strMessage As String = ""
If doorConflictList.Count > 0 Then
For i = 0 To doorConflictList.Count - 1
strMessage += doorConflictList.GetKey(i) & vbCrLf
Dim theConflicts As SortedList = _
CType(doorConflictList.GetByIndex(i), SortedList)
If theConflicts.Count > 0 Then
For m = 0 To theConflicts.Count - 1
strMessage += " " & theConflicts.GetByIndex(m) &
vbCrLf
Next
End If
Next
End If
MessageBox.Show(strMessage)
End Sub

TIA
John
Nov 21 '05 #1
1 1622
J L
Opps...embarrasing...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 doorConflictList be keyed on a door
ID and contain a sorted list called conFlictList. I wrote this
expecting the following

doorConflictList 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conFlictList As New SortedList
Dim doorConflictList 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.Clear()
For i = 0 To door
conFlictList.Add("Key " & i.ToString, "Value " &
i.ToString)
Next
doorConflictList.Add("Door " & door.ToString, conFlictList)
Next
Dim strMessage As String = ""
If doorConflictList.Count > 0 Then
For i = 0 To doorConflictList.Count - 1
strMessage += doorConflictList.GetKey(i) & vbCrLf
Dim theConflicts As SortedList = _
CType(doorConflictList.GetByIndex(i), SortedList)
If theConflicts.Count > 0 Then
For m = 0 To theConflicts.Count - 1
strMessage += " " & theConflicts.GetByIndex(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
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
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...
57
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
5
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...
10
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...
3
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...
4
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...
1
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...
8
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;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
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...

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.