Skip to main content

Posts

Showing posts from June, 2012

Linked List Quiz - Part I

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 recursivelyReverse the list iterativelyFind if the list is cyclicFind the node that causes the cycle (and break the cycle)Reverse every K nodes in the listI 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> class LinkedList { public:…