Implement a bidirectional linked list

A bidirectional linked list is the same as a singular linked list except that there are two links between two nodes. Here is the specification of my BiLinkedList. BiLinkedList(), Create an empty BiLinkedList. BiLinkedList(const BiLinkedList& list), Create a BiLinkedList from another BiLinkedList list. BiLinkedList(const T& value), Create a BiLinkedList whose first element is value. BiLinkedList(const T values[], size_t size), Create a BiLinkedList from an array values of size size. const BiLinkedList& operator=(const BiLinkedList& list), Support BiLinkedList assignment.

Implement a binary search tree

A binary search tree is very useful in solving the real world problems. The red-black tree is one kind of binary search tree. For more information about binary search tree, please visit the wikipedia. Here is the specification of my binary search tree. BinarySearchTree(), Create an empty binary search tree. BinarySearchTree(const T& root_val), Create an binary search tree whose root node is constructed from root_val. BinarySearchTree(const T values[], const size_t& size), Create an binary search tree from an array values.

Implement a circular linked list

A circular linked list is the same as a singular linked list except that there last node points to the first node. Here is the specification of my CiLinkedList. CiLinkedList(), Create an empty CiLinkedList. CiLinkedList(const CiLinkedList& list), Create a CiLinkedList from another CiLinkedList list. CiLinkedList(const T& value), Create a CiLinkedList whose first element is value. CiLinkedList(const T values[], size_t size), Create a CiLinkedList from an array values of size size.

Implement a queue

A queue is based on the Linked List. The most explicit feature of a queue is FIFO(First in first out). Here is the specification of my Queue. Queue(), Create an empty queue. Queue(const T& value), Create a queue whose first element is value. Queue(const T values[], const size_t& size), Create a queue from an array values whose size is size. Queue(const Queue<T>& queue), Create a queue from another queue. const Queue<T>& operator=(const Queue<T>& queue), Support queue assignment.

Implement a queue using two stacks

A queue can be implemented using two stacks. One stack store the elements appended to the queue. The other stack store the elements to be popped from the queue. Here is the specification of my Queue. StQueue(), Create an empty queue. StQueue(const T& value), Create a queue whose first element is value. StQueue(const T values[], const size_t& size), Create a queue from an array values whose size is size. StQueue(const StQueue<T>& queue), Create a queue from another queue.

Implement a singular LinkedList

LinkedList is a very common data structure. Three years ago, I could write a singular LinkedList very quickly in C/C++. But the code is ugly and very ineffecient. Now I am going to implement a singular LinkedList in C++ in order to cracking the interview. Here is the specification of my LinkedList. LinkedList(), Create an empty LinkedList. LinkedList(const LinkedList& list), Create a LinkedList from another LinkedList list. LinkedList(const T& value), Create a LinkedList whose first element is value.

Implement a stack

A stack is based on the Linked List. The most explicit feature of a stack is FILO(First in last out). Here is the specification of my Stack. Stack(), Create an empty stack. Stack(const T& value), Create a stack whose first element is value. Stack(const T values[], const size_t& size), Create a stack from an array values whose size is size. Stack(const Stack<T>& stack), Create a stack from another stack. const Stack<T>& operator=(const Stack<T>& stack), Support stack assignment.

Implement the sorting algorithms

The sorting algorithms are very important in programming interview. I have to be able to write them on a paper without even an error. Bubble Sort The immediate thought of bubble sort is that swapping the ajacent elements if they are of the wrong order in each pass until there are no swapping. For example, consider the array [5, 1, 4, 2, 8], First pass: [5, 1, 4, 2, 8] => [1, 5, 4, 2, 8] => [1, 4, 5, 2, 8] => [1, 4, 2, 5, 8] => [1, 4, 2, 5, 8]

Initialized before used

For constructor In the constructor, the statements in the body are assignments, not initializations. #include <iostream> class Girl { public: Girl(std::string name, int age) { name_ = name; // These are assignments, not initilizations. age_ = age; } private: std::string name_; int age_; }; If you do this, the program will be very slow.When calling the constructor, the program will call the default construtors to initialize the members, and then enter the body of the constructor.

More consts enums inlines and less #defines

This is an old topic. For constants Consider a macro below. #define PI 3.14 There are several drawbacks when using a macro. It’s hard to debug.As we all know, the macros are resolved by the preprocessor and the compiler know nothing about them.When you get an error when compiling the program, the error message may refer to 3.14 but not PI because PI is not in the symbol table.