Hi.
Mostly I program in C++, and I'm not fluent in C# and .NET. In my last
project I began to use LinkedList<and suddenly noticed that can't
find a way to sort it. Does it mean I must implement sorting for
LinkedList<myse lf?
Thanks in advance
Martin 20 20915
"martin-g" <ma******@mail. ruwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...
Hi.
Mostly I program in C++, and I'm not fluent in C# and .NET. In my last
project I began to use LinkedList<and suddenly noticed that can't
find a way to sort it. Does it mean I must implement sorting for
LinkedList<myse lf?
Thanks in advance
Martin
So it would appear.
Perhaps this article would be helpful to you: http://msdn2.microsoft.com/en-us/library/6tc79sx1.aspx
pvdg42 wrote:
So it would appear.
Perhaps this article would be helpful to you:
http://msdn2.microsoft.com/en-us/library/6tc79sx1.aspx
Thank you for answer. That's really wild... Looking through the article
I couldn't eventually select the collection class of my need. On the
one hand I want an item to be added to the container at constant time
at any position, so must use LinkeList<>. On the other hand I want to
sort the container, so I must use List<>. FCL has really strange
container organization... Only now I understood: I love STL very much...
martin-g wrote:
pvdg42 wrote:
So it would appear.
Perhaps this article would be helpful to you: http://msdn2.microsoft.com/en-us/library/6tc79sx1.aspx
Thank you for answer. That's really wild... Looking through the article
I couldn't eventually select the collection class of my need. On the
one hand I want an item to be added to the container at constant time
at any position, so must use LinkeList<>. On the other hand I want to
sort the container, so I must use List<>. FCL has really strange
container organization... Only now I understood: I love STL very much...
So you want constant time insertions and the ability to sort the
collection. The List<collection sounds like a good match.
Insertions are usually O(1) and you can call the Sort method to sort
the collection. Have you looked at SortedDictionar y yet? Insertions
are a bit slower, but the items are always stored in order so there's
no need to perform a separate sort operation.
Brian
Brian Gideon <br*********@ya hoo.comwrote:
Thank you for answer. That's really wild... Looking through the article
I couldn't eventually select the collection class of my need. On the
one hand I want an item to be added to the container at constant time
at any position, so must use LinkeList<>. On the other hand I want to
sort the container, so I must use List<>. FCL has really strange
container organization... Only now I understood: I love STL very much...
So you want constant time insertions and the ability to sort the
collection. The List<collection sounds like a good match.
Insertions are usually O(1) and you can call the Sort method to sort
the collection. Have you looked at SortedDictionar y yet? Insertions
are a bit slower, but the items are always stored in order so there's
no need to perform a separate sort operation.
Insertions into a List<are certainly *not* O(1) in general. When
adding to the end of the list, the additions will be cheap if there's
enough room in the buffer. Otherwise, it requires a copy of all the
items after the new entry (or all the items if a new buffer is
required).
The MSDN docs say it's an O(n) operation too.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon wrote:
Brian Gideon <br*********@ya hoo.comwrote:
Thank you for answer. That's really wild... Looking through the article
I couldn't eventually select the collection class of my need. On the
one hand I want an item to be added to the container at constant time
at any position, so must use LinkeList<>. On the other hand I want to
sort the container, so I must use List<>. FCL has really strange
container organization... Only now I understood: I love STL very much...
So you want constant time insertions and the ability to sort the
collection. The List<collection sounds like a good match.
Insertions are usually O(1) and you can call the Sort method to sort
the collection. Have you looked at SortedDictionar y yet? Insertions
are a bit slower, but the items are always stored in order so there's
no need to perform a separate sort operation.
Insertions into a List<are certainly *not* O(1) in general. When
adding to the end of the list, the additions will be cheap if there's
enough room in the buffer. Otherwise, it requires a copy of all the
items after the new entry (or all the items if a new buffer is
required).
The MSDN docs say it's an O(n) operation too.
Yeah, wow, I'm not sure what I was thinking when I wrote that. In
fact, my whole post doesn't make any since...beginni ng, middle, and
end. That's one of those you just wish you could take back. Ya think
I can talk Google into deleting that one :)
Jon wrote:
Insertions into a List<are certainly *not* O(1) in general. When
adding to the end of the list, the additions will be cheap if there's
enough room in the buffer. Otherwise, it requires a copy of all the
items after the new entry (or all the items if a new buffer is
required).
The MSDN docs say it's an O(n) operation too.
So, List<isn't a linked list, it's an array...? I suppose it would
have to be, if it's meant to be the "first choice" collection for
general use.
Does Framework 2.0 even provide a true link list? Dumb question, I
know, but we're still on 1.1.... :-)
"Bruce Wood" <br*******@cana da.comwrote:
>Does Framework 2.0 even provide a true link list?
LinkedList<T>, which was already mentioned earlier in this thread...
Bruce Wood wrote:
So, List<isn't a linked list, it's an array...? I suppose it would
have to be, if it's meant to be the "first choice" collection for
general use.
Yes, List<is based on array.
Does Framework 2.0 even provide a true link list? Dumb question, I
know, but we're still on 1.1.... :-)
I was on 1.1 too, and decided to turn to 2.0 only for its LinkedList<>
generic collection. And some time later realized it's not the linked
list of my dreams.
Jon Skeet [C# MVP] wrote:
Well, System.Collecti ons.LinkedList still exists, and there's a generic
LinkedList as well.
I do apologise - of course there isn't a System.Collecti ons.LinkedList,
I don't know what I was thinking of...
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sparko |
last post by:
My Xml is as follows;
<root>
<st id="1">
<rt id="1">
<cr id="1" ca_w="" ca_x="" ca_y="" ca_z="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
|
by: Dave |
last post by:
Hello all,
I'm pondering why the default underlying container for std::priority_queue<>
is std::vector<>. It would seem that inserts are liable to happen anywhere,
which would make std::list<> a superior alternative. Why factors am I not
considering here? Why in the general case would std::vector<> be best?
Thanks,
Dave
|
by: ahaque38 |
last post by:
Hello.
Using A2K SP3, I am having the following problem with a report using
"Sorting and Grouping".
I have recently added a grouping in the reports for
"Category2<>'CONTRACTS'".
I have reports at the plan (overall totals), department and division
levels which have sorting and grouping implemented with this new
|
by: Iron Moped |
last post by:
I'm airing frustration here, but why does LinkedList<not support the
same sort and search methods as List<>? I want a container that does not
support random access, allows forward and reverse traversal and
natively supports sorting, i.e., STL's list<T>. There isn't even a set of
algorithms that would allow me to easily sort a generic collection.
System.Array has a robust set of static algorithms, why not extend this to
ICollection?
|
by: Zytan |
last post by:
The docs for List say "The List class is the generic equivalent of the
ArrayList class." Since List<is strongly typed, and ArrayList has
no type (is that called weakly typed?), I would assume List<is far
better. So, why do people use ArrayList so often? Am I missing
somehing? What's the difference between them?
Zytan
| |
by: Lee Crabtree |
last post by:
This seems inconsistent and more than a little bizarre.
Array.Clear sets all elements of the array to their default values (0,
null, whatever), whereas List<>.Clear removes all items from the list.
That part makes a reasonable amount of sense, as you can't actually take
items away from an Array. However, there doesn't seem to be a way to
perform the same operation in one fell swoop on a List<>.
For example:
|
by: Jon Slaughter |
last post by:
When I create a LinkedList<what is a LinkedListNode compared to a value?
AddFirst(54) for example, does it turn 54 into a node or what? I'm trying ot
find out what the LinkedListNode is specifically for? Basically just a
wrapper around the reference type?
|
by: Alberto Bencivenni |
last post by:
Hi All,
Is there a reason why it is not possible to serialize a geenric
LinkedList<Tobject containing a custom class marke serializable?
Thanks,
Alberto
|
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,...
|
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: 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: 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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |