473,394 Members | 1,752 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,394 software developers and data experts.

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
'ListMemberObject' 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
ListMemberObject 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.BinarySearch for the express
purpose of only adding unique values,

public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullException();
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.BinarySearch(idComparer );
if(binSrch < 0)
{
base.Insert(~binSrch, o);
result = ~binSrch;
}
return result;
}

What to do?
TIA

Robert Zurer

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

"Robert Zurer" <ro****@zurer.com> wrote in message
news:uB**************@TK2MSFTNGP10.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
'ListMemberObject' 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
ListMemberObject 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.BinarySearch for the express
purpose of only adding unique values,

public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullException();
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.BinarySearch(idComparer );
if(binSrch < 0)
{
base.Insert(~binSrch, 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**********@businesslogic.co.uk> wrote in message
news:u9**************@tk2msftngp13.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.com> wrote in message
news:uA**************@TK2MSFTNGP11.phx.gbl...
Thanks for the suggestion, do you have any links to a good implementation??

Robert Zurer
"Horatiu Ripa" <ho**********@businesslogic.co.uk> wrote in message
news:u9**************@tk2msftngp13.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.com> wrote in message
news:uA**************@TK2MSFTNGP11.phx.gbl...
Thanks for the suggestion, do you have any links to a good implementation??

Robert Zurer
"Horatiu Ripa" <ho**********@businesslogic.co.uk> wrote in message
news:u9**************@tk2msftngp13.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
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
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...
1
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...
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...
9
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...
11
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...
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:
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...
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
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
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
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...
0
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,...
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...

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.