473,887 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorted List Problem

Assuming that I have created a strongly typed collection and overridden the
appropriate methods, i.e. this[], Add, Insert etc., so that a sort order is
maintained, it's still very possible for a property of the
'ListMemberObje ct' which is instrumental in the sort to be modified
unbeknownst to the list thereby defeating the sort.

One way to keep the list sorted is to add a 'ParentList' property to the
ListMemberObjec t and notify that ParentList to sort itself in every set
method of the list object. That would repeat code everywhere and is
extremely yucky.

I've looked at a few implementations of creating a sorted list, most notably

http://www.codeproject.com/useritems/SortableList.asp

but the problem is not addressed.

In a related vein. If I want to use ArrayList.Binar ySearch for the express
purpose of only adding unique values,

public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullExc eption();
IComparer idComparer = new IDComparer();

Sort(idComparer );
//if I call this here the application dies a slow and painful death with
a large list
//if I don't call it I'm not absolutely sure my list is sorted properly

int binSrch = this.BinarySear ch(idComparer );
if(binSrch < 0)
{
base.Insert(~bi nSrch, o);
result = ~binSrch;
}
return result;
}

What to do?
TIA

Robert Zurer

Nov 15 '05 #1
4 2523
Why didn't you implement a binary tree (ordered)? Well implemented all your
troubles will dissapear.
--
Horatiu Ripa

"Robert Zurer" <ro****@zurer.c om> wrote in message
news:uB******** ******@TK2MSFTN GP10.phx.gbl...
Assuming that I have created a strongly typed collection and overridden the appropriate methods, i.e. this[], Add, Insert etc., so that a sort order is maintained, it's still very possible for a property of the
'ListMemberObje ct' which is instrumental in the sort to be modified
unbeknownst to the list thereby defeating the sort.

One way to keep the list sorted is to add a 'ParentList' property to the
ListMemberObjec t and notify that ParentList to sort itself in every set
method of the list object. That would repeat code everywhere and is
extremely yucky.

I've looked at a few implementations of creating a sorted list, most notably
http://www.codeproject.com/useritems/SortableList.asp

but the problem is not addressed.

In a related vein. If I want to use ArrayList.Binar ySearch for the express
purpose of only adding unique values,

public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullExc eption();
IComparer idComparer = new IDComparer();

Sort(idComparer );
//if I call this here the application dies a slow and painful death with a large list
//if I don't call it I'm not absolutely sure my list is sorted properly
int binSrch = this.BinarySear ch(idComparer );
if(binSrch < 0)
{
base.Insert(~bi nSrch, o);
result = ~binSrch;
}
return result;
}

What to do?
TIA

Robert Zurer

Nov 15 '05 #2
Thanks for the suggestion, do you have any links to a good implementation? ?
Robert Zurer
"Horatiu Ripa" <ho**********@b usinesslogic.co .uk> wrote in message
news:u9******** ******@tk2msftn gp13.phx.gbl...
Why didn't you implement a binary tree (ordered)? Well implemented all your troubles will dissapear.
--

Nov 15 '05 #3
try
http://www.javacommerce.com/tutorial...es/c11/s4.html

You don't have to use that implementation but it gives you an idea.

--
Horatiu Ripa
Software Development Manager
Business Logic Systems LTD
21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
Phone/Fax: +40 264 590703
Web: www.businesslogic.co.uk

This email (email message and any attachments) is strictly confidential,
possibly privileged and is intended solely for the person or organization to
whom it is addressed. If you are not the intended recipient, you must not
copy, distribute or take any action in reliance on it. If you have received
this email in error, please inform the sender immediately before deleting
it. Business Logic Systems Ltd accepts no responsibility for any advice,
opinion, conclusion or other information contained in this email or arising
from its disclosure.

"Robert Zurer" <ro****@zurer.c om> wrote in message
news:uA******** ******@TK2MSFTN GP11.phx.gbl...
Thanks for the suggestion, do you have any links to a good implementation? ?

Robert Zurer
"Horatiu Ripa" <ho**********@b usinesslogic.co .uk> wrote in message
news:u9******** ******@tk2msftn gp13.phx.gbl...
Why didn't you implement a binary tree (ordered)? Well implemented all

your
troubles will dissapear.
--


Nov 15 '05 #4
The add, search, getnext methods are trivial to implement - recursively -
and you can get them from there.
But the remove function is tricky and quite nice, and not implemented
there!!!

--
Horatiu Ripa
Software Development Manager
Business Logic Systems LTD
21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
Phone/Fax: +40 264 590703
Web: www.businesslogic.co.uk

This email (email message and any attachments) is strictly confidential,
possibly privileged and is intended solely for the person or organization to
whom it is addressed. If you are not the intended recipient, you must not
copy, distribute or take any action in reliance on it. If you have received
this email in error, please inform the sender immediately before deleting
it. Business Logic Systems Ltd accepts no responsibility for any advice,
opinion, conclusion or other information contained in this email or arising
from its disclosure.

"Robert Zurer" <ro****@zurer.c om> wrote in message
news:uA******** ******@TK2MSFTN GP11.phx.gbl...
Thanks for the suggestion, do you have any links to a good implementation? ?

Robert Zurer
"Horatiu Ripa" <ho**********@b usinesslogic.co .uk> wrote in message
news:u9******** ******@tk2msftn gp13.phx.gbl...
Why didn't you implement a binary tree (ordered)? Well implemented all

your
troubles will dissapear.
--


Nov 15 '05 #5

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

Similar topics

57
3642
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
10
15153
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
22083
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...
1
1657
by: J L | last post by:
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
4
1868
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
1596
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>
9
2213
by: ECUweb | last post by:
Hi, I need to sort out a list of records based on the field "Weight" and then allocate points (from 1 to 10) to each record (in another field "Points") depending on the position of the record in the sorted list. Sorting out the list is not the problem for me but allocating the points is. The other problem is that when for example two records have the same weight, the allocated points should be the same, even when in the sorted list one of the...
11
11436
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the keys are numeric, the keys themselves are ordered in the dictionary. part of my code is like this: radix={} for i in range(256):
8
2601
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
9799
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
11173
Oralloy
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...
1
10877
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,...
0
10434
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 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...
0
9593
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
7143
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
5810
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
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4633
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

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.