20
votes
Accepted
IList<T> implementation
This is called a doubly linked list. List<T> is basically a wrapper around an array. The only operations where you can hope to be faster are insertions and ...
15
votes
Accepted
Moving elements satisfying a predicate from one container to another
Sorting the source is not specified as a requirement, so it seems that std::partition would do the necessary job more efficiently. As a perk benefit, ...
15
votes
Accepted
Ring Buffer Implementation in C++14
Coding idiomatically
Remember that #pragma once isn't standard (unlike include guards).
If you only intend your class works on major compilers, you can use ...
13
votes
Accepted
StackList<T> implementation
Issues
public void Push(T item)
{
_stackList.Insert(0, item);
}
The hurts the stack list.
It would be much easier if you just added new items at the end of ...
11
votes
Accepted
Map with case insensitive get, remove and containsKey
You can't do that with HashMap. Use a TreeMap instead:
...
11
votes
Accepted
Multi-dimensional container using operator[]
This would be much easier to review if there were more useful comments (saying "forward declarations" in front of a bunch of forward declarations is not all that useful) or - more importantly - some ...
10
votes
Accepted
BTreeMap as a multimap in Rust
Idiomatic Rust style is to place braces on same line. When the function definition gets longer than one line then the brace lives on the next line all on its own.
Learn and love the ...
10
votes
reverse a list of generic type
No and no. This is a very inefficient way to reverse, for example, a dynamic array based list (it's a different story with a linked list). With a dynamic array based (e.g. ...
10
votes
Accepted
reverse a list of generic type
Java doesn't handle recursion very well. And by not very well I mean it should be avoided almost every time where you cannot limit the depth to something small. To show you how bad it is let's take a ...
9
votes
List<T> implementation for VB6/VBA
Your implementation of Sort would be optimised by implementing IndexOfMin so that ...
9
votes
Moving elements satisfying a predicate from one container to another
Complexity
std::sort has at runtime complexity of at least \$\mathcal{O}(n \log{n})\$, and requires that the given container type provides random access iterators (...
9
votes
Alternating items in a collection
Not a fan of LINQ, yet? Then look here... You could start by grouping Child by Sex into a new lookup, this would replace the two ...
9
votes
Accepted
Using Method Chaining To Alter Last Item Added To Collection
Aside from optional arguments that may or may not be used, fluent API is very useful when it comes to open arguments, and it's also easy to expand and maintain.
Your approach is very good. You might ...
9
votes
Accepted
Generic Doubly Linked-list implementation in C++
Identifiers that start with a double underscore, or a single underscore followed by a capital letter, are reserved for use by the implementation. Your use of __T ...
8
votes
StackList<T> implementation
I don't know why you are going through all this trouble to add an indexer. Stack<T> has an extension method called ...
8
votes
Accepted
Double-ended queue and iterators
I really recommend using an explicit type for your linked-list node:
...
8
votes
Accepted
Find a Value in a Container
Parameters
As a starting point, I'd usually advise against passing bools as parameters--especially passing more than one bool ...
8
votes
Alternating items in a collection
My only comment is don't mutate the input and then return it.
private List<Child> MixGender(List<Child> children)
Return a fresh ...
8
votes
Accepted
Class containers, filtering and coding practices
To enforce a collection-like functionality would I implement a custom made ICollection interface in each container class.
While an ICollection interface is nice ...
8
votes
IList<T> implementation
You've essentially built a doubly-linked list that also performs its own memory management.
Regarding linked lists:
This makes indexing is an \$O(n)\$ operation, compared to \$O(1)\$ for ...
7
votes
Accepted
Finding anagrams
Inefficient algorithm
Your algorithm takes \$O(n^2)\$ time, where \$n\$ is the number of words. You could do this in \$O(n)\$ time with a small modification.
Instead of storing words into your ...
7
votes
Accepted
A Java subclass of ArrayList that supports rotation in constant time
Your code does not throw UnsupportedOperationException for addAll, when you don't guarantee the index of the ordering. The ...
7
votes
Accepted
Find maximum value of Point represented by an Array of values for each coordinate
I'm not a Lisp guy, but parenthesis are powerful. Change this:
sum = A[i] + A[j] + (j - i)
to that:
...
7
votes
Accepted
Custom struct design: Range
Only targeting public struct Range
If possible a struct should be immutable so you shouldn't let a user of this struct set the ...
7
votes
Accepted
Get a random member of a container
Long name
ThorsAnvil::Util::getRandomIteratorFromContainer is a really long name. I suggest something like getRandomElement or ...
6
votes
Accepted
Custom sorting of dates
A Comparator is the correct approach, you just need to mod the month by the current month before comparing them. The easiest way to do this is to introduce a static ...
6
votes
Chunking a list into separate lists of 5, and then iterating through each
Separate the mechanics and the semantics of the code. Here's my very well used Batch<T> extension method on ...
6
votes
Accepted
Alternating items in a collection
It looks like the core of your problem is taking two sequences and "interleaving" them, alternating elements for as long as possible, but allowing for the sequences to be different lengths. Your ...
6
votes
Accepted
Pass IEnumerable<T> as an argument of method and repository pattern
There is no general rule for using IEnumerable or not but there is one that says that you should use the most abstract representation of something because it gives ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
collections × 346java × 103
c++ × 91
c# × 79
performance × 41
array × 30
c++11 × 23
hash-map × 23
generics × 17
iterator × 17
python × 16
object-oriented × 16
vba × 15
.net × 15
reinventing-the-wheel × 14
algorithm × 13
sorting × 12
vectors × 12
linked-list × 11
c++17 × 11
beginner × 10
c++14 × 10
c × 9
template × 9
php × 8