Array of Linked Lists C++

That returns a bunch of unallocated pointers. Your top level array is fine, but its elements are still uninitialized pointers, so when you do this: You invoke undefined behavior. You’re dereferencing an uninitialized pointer. You allocated the array properly, now you need to allocate each pointer, i.e., As an aside, I realize that you’re learning, … Read more

How is Python’s List Implemented?

It’s a dynamic array. Practical proof: Indexing takes (of course with extremely small differences (0.0013 µsecs!)) the same time regardless of index: I would be astounded if IronPython or Jython used linked lists – they would ruin the performance of many many widely-used libraries built on the assumption that lists are dynamic arrays

Iterator for a linkedlist

1) SortedLinkedList extends BasicLinkedList but both have this is wrong. If you want to inherit those field in the sub class, you should mark the variables as protected in the super class and remove them from the subclass. 2) Same goes for private class Node. You are declaring the Node class in both the SortedLinkedList and BasicLinkedList. What you should do is declare … Read more

Destructor for a doubly-linked list that points to its value

You need to pair each new with exactly one delete. That is, you probably don’t want to delete prev (this node already was deleted) but you want to delete value. Well, I’d embed the value into the object and not point to it: If the value absolutely needs to be a pointer, I’d use a std::unique_ptr<int> (or, if you need to use C++ 2003, a std::auto_ptr<int>).