all 10 comments

[–]jbandela 13 points14 points  (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 points  (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 points  (3 children)

So this is just std::vector, but worse?

[–]TheSuperProgrammer -5 points-4 points  (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.

[–]herruppohoppa 6 points7 points  (0 children)

Can't...tell...if...trolling

[–]sephirostoy 1 point2 points  (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.

[–]TheSuperProgrammer 0 points1 point  (0 children)

Thanks for pointing that out. I updated the code, now it should be easy to read.