Table of contents Circular linked list Linked list nth node from the end Reverse linked list Reverse linked list recursively Circular linked list This is a typical interview question. Given a singly linked list. Write a function that detects if the linked list is circular (has a loop) which means the last node points to

Introduction The distinction between regular and static variables in C++ is a such a confusing topic for many beginners including students and programers. In this short article, I am going to provide an brief explanation and hopefully remove the ambiguity. I personally believe that the root cause of confusion is due to lack of context.

Amicable Numbers Definition Two positive integer numbers (m, n) are amicable if the sum of the proper divisors of (m) is equal to (n) and the sum of the proper divisors of (n) is equal to (m). A proper divisor of a number does not include the number itself. For example, the proper divisors of

Matlab mex functions can be used to extend Matlab functionality or to improve performance by using compiled code as opposed to interpreted matlab syntax. Using mex functions is explained in many places on the web however the following is a simple template example to demonstrate that:

Problem Write a C++ function to copy an existing string. Do not use built in functions. Solution This is a straight forward question and to my surprise I was asked this question in a site interview. If you are not prepared you might stumble on the easy ones. The idea is to allocate memory for

Problem Given a one dimensional integer array of 9 elements. Write a function to map the array into a row major 3×3 two dimensional array Solution If you are familiar with 3D graphics API like DirectX or OpenGL they store 4×4 transformation matrices as a linear array of 16 elements. In DirectX the format is

Question In C++ what is the difference between copy constructor and assignment operator. If they are created for you by default then why do we need to create them in the first place. Assignment operator vs copy constructor Copy constructors and assignment operators are created by default even if you do not implement your own.

Problem Write a C++ program to count the number of 2’s between 0 and (n) where (n) is a positive integer. Solution We need two loops, one goes from 0 to n and the other one examines the number digit by digit. One way to get the decimal digits of a number is to shift

Problem Write a C++ recursive function to convert a character string into capital letters. Solution Instead of looping in the string character by character we can recursively call a function while advancing an index each time. Once the index reaches the end of the string we stop recursion. Converting a letter into capital case in

Problem Write a recursive function to compute the product of two positive integers. Solution The product of two positive integers (A*B) is nothing but the sum of the first integer (A), (B) times Code Here is the code in C++