A short while back, Azhagu quizzed me on linked list based problems; singly linked list. I am recording those problems, solutions and my experience as a two part series. In the first part, I am introducing the linked list class, which I wrote for packaging the implementation of the solutions. This class pertains to the context of the problem(s) and cannot be used as a general purpose linked list. A std::list might more pertinent in the context of the general purpose implementation of a list. Here are some of the problems that Azhagu asked me to solve:- Reverse the list recursively Reverse the list iteratively Find if the list is cyclic Find the node that causes the cycle (and break the cycle) Reverse every K nodes in the list I will be solving reversing the list (both iteratively and recursively) and finding if the list is cyclic problems in this episode. #pragma once #include <iostream> #include <vector> using namespace std; template<typename T> clas...
Another effective [debugging] technique is to explain your code to someone else. This will often cause you to explain the bug to yourself. Sometimes it takes no more than a few sentences, followed by an embarrassed "Never mind. I see what's wrong. Sorry to bother you." This works remarkbly well; you can even use non-programmers as listeners. - From "The Practice of Programming" by Brian W Kernighan & Rob Pike.