Skip to main content
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 ...
Peter Taylor's user avatar
  • 24.1k
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, ...
vnp's user avatar
  • 56.6k
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 ...
Calak's user avatar
  • 2,331
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 ...
t3chb0t's user avatar
  • 44.3k
12 votes
Accepted

Map with case insensitive get, remove and containsKey

You can't do that with HashMap. Use a TreeMap instead: ...
Andreas's user avatar
  • 401
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 ...
indi's user avatar
  • 11.4k
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 ...
Shepmaster's user avatar
  • 8,658
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. ...
VisualMelon's user avatar
  • 7,431
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 ...
Imus's user avatar
  • 4,297
9 votes

List<T> implementation for VB6/VBA

Your implementation of Sort would be optimised by implementing IndexOfMin so that ...
Mark Hurd's user avatar
  • 326
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 (...
hoffmale's user avatar
  • 6,498
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 ...
t3chb0t's user avatar
  • 44.3k
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 ...
iSR5's user avatar
  • 5,378
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 ...
1201ProgramAlarm's user avatar
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 ...
Ron Beyer's user avatar
  • 1,061
8 votes
Accepted

Double-ended queue and iterators

I really recommend using an explicit type for your linked-list node: ...
coderodde's user avatar
  • 28.7k
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 ...
Jerry Coffin's user avatar
  • 33.6k
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 ...
paparazzo's user avatar
  • 6,016
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 ...
Mathieu Guindon's user avatar
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 ...
Pieter Witvoet's user avatar
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: ...
I'll add comments tomorrow's user avatar
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 ...
Heslacher's user avatar
  • 50.4k
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 ...
Indiana Kernick's user avatar
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 ...
RobH's user avatar
  • 17k
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 ...
benj2240's user avatar
  • 1,026
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 ...
t3chb0t's user avatar
  • 44.3k
6 votes
Accepted

LinkedList Swift Implementation

Nested types All “dependent” types are defined within the scope of LinkedList, which is good. To reference those types from within ...
Martin R's user avatar
  • 23.3k
6 votes

Reviewing custom array List class of java

The CustomArrayList API is inconsistent because I can declare a list of type E to add elements of type ...
Roman's user avatar
  • 2,843
6 votes

Hash table implemented in C with open addressing

Good header file .... aside from the struct definitions that belong in the .c file. Weak hash OP's code only uses the least few bits of ...
chux - Reinstate Monica's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible