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
15 votes

Writing a program to read a maximum of 99 elements in an iteration from a list

First things first, I feel the biggest problem about your code is that your comments lie. ...
h.j.k.'s user avatar
  • 19.2k
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
  • 54.7k
14 votes
Accepted

Writing a program to read a maximum of 99 elements in an iteration from a list

Bugs Your code doesn't actually do what it says it will do. The problems are here: ...
JS1's user avatar
  • 28.4k
13 votes

Writing a program to read a maximum of 99 elements in an iteration from a list

Let's take a look at naming and style. public class OptimizeReadingList { That sounds like a function, not like a class. ...
Mast's user avatar
  • 13k
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
  • 44k
13 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,303
11 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
  • 391
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
  • 9,621
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,528
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,421
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,287
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,448
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
  • 44k
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,093
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
Accepted

Loop through column cells and compare value with a Collection

For a lot of data dictionaries are faster than collections, and much more convenient as @RubberDuck mentioned. Lookup times are almost instantaneous, IF you do a lot of lookups, but both collections ...
paul bica's user avatar
  • 1,154
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,006
8 votes
Accepted

Double-ended queue and iterators

I really recommend using an explicit type for your linked-list node: ...
coderodde's user avatar
  • 26.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.3k
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
  • 5,946
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

C# Tree implementation

Comments Comments should clarify the code, not simply restate it. You have a lot of comments like this. ...
RubberDuck's user avatar
  • 30.8k
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 ...
JS1's user avatar
  • 28.4k
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 ...
Pimgd's user avatar
  • 22.3k
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.1k

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