In C++ a class with at least one pure virtual function is called abstract class. You can not create objects of that class, but may only have pointers or references to it. If you are deriving from an abstract class, then make sure you override and define all pure virtual functions for your class. From … Read more
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
Deque is short for “double ended queue”. With an ordinary queue, you add things to one end and take them from the other. With a double ended queue, you can add things to either end, and take them from either end. That makes it a bit more versatile; for example, you could use it as … Read more
In the absolute worst case, a binary tree with N elements would be like a linked list.Hence, there would be N levels, and a search would take N traversals. That’s why it’s O(N) in the worst case.And this is why we need to balance the trees to achieve O(log N) search.
Write it like this: And similarly for other member functions. But you’ll run into another problem – declarations and definitions of a template can’t be separated to different files.
A Tree is just a restricted form of a Graph. Trees have direction (parent / child relationships) and don’t contain cycles. They fit with in the category of Directed Acyclic Graphs (or a DAG). So Trees are DAGs with the restriction that a child can only have one parent. One thing that is important to … Read more
Edit Please read the comments to this answer. People claim I did not do proper tests. I agree this should not be an accepted answer. As I was learning I did some tests and felt like sharing them. Original answer… I found interesting results: Linked list (3.9 seconds) List (2.4 seconds) Even if you only … Read more
It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size. Big-O notation doesn’t mean an exact equation, but rather a bound. For instance, the output of the following functions is all O(n): Because as you increase x, their outputs all increase linearly – if there’s … Read more
This looks like a good candidate for the TAILQ_* ? “man queue” will give more details – there are simple lists, tail queues and circular queues there. Those are the macros that you’d need to bolt on your own structures, not classes of course. The code for your scenario will look something like this (I … Read more
I’ve created simple binary tree printer. You can use and modify it as you want, but it’s not optimized anyway. I think that a lot of things can be improved here 😉 Output 1 : Output 2 :