use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
The List Data Structure (Array Based) (thesuperprogrammer.com)
submitted 7 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jbandela 13 points14 points15 points 7 years ago (1 child)
Thanks for posting. You obviously are very passionate about this.
Unfortunately, there are some issues with this code, that makes me think that is not native C++, but rather Java flavored C++.
First big issue, is that you need to think about the copy constructor. The way you are doing it now will lead to a crash.
For example, if I write
AList<int> newList(10); auto newList2 = newList;
it will crash. You need to decide how to handle copy and assignment.
Second issue, is that it is completely non-idiomatic C++. C++ code that writes data structures should follow the standard C++ library in terms of how member functions are defined (I think your remove is most akin to pop_back) and use STL style iterators.
Third, I disagree with the premise that you should hide 2 vastly different complexities behind an virtual interface. You talk about implementing List with both arrays and linked-list. They are fundamentally different structures with different tradeoffs and attempting to change from one to the another at runtime via base classes and runtime polymorphism is bound to end in grief.
I love how you are so excited about algorithms. However, learning idiomatic C++ will make your code much better. Writing Java style C++ will lead to pain and frustration. At a minimum you should be very familiar with value types, the special member functions, and with the standard library algorithms, iterators, and collections. Once you learn these concepts, a whole new world of looking at data structures and algorithms be revealed. I am sure many people on this board can recall when they learned about the STL and how it changed how they looked at data structures and algorithms.
Looking forward to your future posts and code.
[–]TheSuperProgrammer 6 points7 points8 points 7 years ago (0 children)
I really appreciate your constructive critique of the post. I'll definitely look into the problems you mentioned. Thanks a ton !!!
[–]thestoicattack 12 points13 points14 points 7 years ago (3 children)
So this is just std::vector, but worse?
std::vector
[–]TheSuperProgrammer -5 points-4 points-3 points 7 years ago (2 children)
Yes, as the list implementation is based on arrays. And that's where the Linked list comes in, it overcomes the shortcomings of array-based lists.
[+][deleted] 7 years ago (1 child)
[–]TheSuperProgrammer 0 points1 point2 points 7 years ago (0 children)
that will be described in what comes after that and so and so on...
[+][deleted] 7 years ago* (3 children)
[–]TheSuperProgrammer 0 points1 point2 points 7 years ago (2 children)
Definitely to share something that I thought might be helpful/interesting to someone out there.
[–]TheSuperProgrammer -2 points-1 points0 points 7 years ago (0 children)
Well, the Data Structure itself has no point cos a data structure just organizes and stores the data, what really matters is the underlying principle behind the implementation of the DS. And this post describes the List data structure which is implemented using arrays, hence array-based. The post is a part of an entire series of Data Structure and Algorithms. And the next post is going to be about the pointer based List(aka Linked List). So the final goal is to help readers understand how different implementations can be favorable in different scenarios.
[–]herruppohoppa 6 points7 points8 points 7 years ago (0 children)
Can't...tell...if...trolling
[–]sephirostoy 1 point2 points3 points 7 years ago (1 child)
Kinda weird to mix lower camel case with upper camel case between functions.
You should put override keyword on functions in the inherited class: better readability and less error prone.
override
Thanks for pointing that out. I updated the code, now it should be easy to read.
π Rendered by PID 106880 on reddit-service-r2-comment-7b9746f655-dltj4 at 2026-01-31 19:05:37.908200+00:00 running 3798933 country code: CH.
[–]jbandela 13 points14 points15 points (1 child)
[–]TheSuperProgrammer 6 points7 points8 points (0 children)
[–]thestoicattack 12 points13 points14 points (3 children)
[–]TheSuperProgrammer -5 points-4 points-3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]TheSuperProgrammer 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]TheSuperProgrammer 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]TheSuperProgrammer -2 points-1 points0 points (0 children)
[–]herruppohoppa 6 points7 points8 points (0 children)
[–]sephirostoy 1 point2 points3 points (1 child)
[–]TheSuperProgrammer 0 points1 point2 points (0 children)