Technology, life, programming, travel and money.

Posts Tagged ‘C++’

Triangle Identification – C++ solution and test code

Here is another interview coding question that I have heard of. You have to write a function to identify the triangle type. You have to return a number between 1 or 4 to identify either a valid triangle type or an error. The solution is very simple requiring only one condensed line of code to identify each triangle type. Two lines of code [...]

Reverse the words in a sentence – C++ solution and test code

Here is a solution to the standard interview questions of reversing the letters in the words of a sentence. It is a more complex version of the even more common "reverse a string" question. I also include my test code. There are two main parts to this. The first identifies where the word boundaries are. The second reverses the letters between [...]

Picking the 5th from last element in a singly linked list

Here's another of those fun coding interview puzzles. The kind that companies like Microsoft or Google might ask you. Given a singly linked list, select the 5th from last element. I'm writing the solution in C++ but the solution in Java would be almost identical. I'm also putting up my test code. The restrictions are - you can only make one [...]

Reverse a linked list – C++ source code

Reversing a linked list is a simple programming problem, which is often an interview question. In this case I'm referring to a singly linked list. I'll provide the C++ solution and the C++ test code. One of the easiest ways to reverse the linked list is to create a new head pointer, iterate through the list removing each item in turn and then [...]

Dijkstra’s Algorithm code in C++

Dijkstra’s Algorithm code in C++

Dijkstra's algorithm is a famous algorithm that calculates the routes and distances from a start node to all other nodes in a connected graph where all the distances are positive. Here is a version which I wrote in C++. My aim here was to try to create a version that was easy to read, rather than the most efficient version. I used the excellent [...]

Select 100 random values from a stream / linked list

Select 100 random values from a stream / linked list

Here's an interesting puzzle / interview question that I heard recently. Problem You have a either a linked list or a stream containing int values. You don't know how large the stream / linked list except that it contains 100 or more values. You need to write a method that selects 100 random values from the stream. You have to write the [...]

QuickSort Implementation Code in C++

I was having a look at the QuickSort algorithm (as you do for fun) and was trying to find a tidy looking implementation in C++. I found a lot of implementations out there but most of them looked far more complicated than I thought they should have been. The QuickSort algorithm as printed in the book looks relatively simple. I wanted a C++ [...]

Writing and releasing a free software tool in two weeks

Writing and releasing a free software tool in two weeks

Two weeks ago I started a mini-project to write a simple piece of software in C#, package it up and release it. Although I had initially given myself two weeks, the actual time I spent on this project was less than a week due to a pest problem, a birthday, and a family visit. The purpose of this project was to learn the basics of a new programming [...]

C# – How to make a window stay on top and become transparent

C# – How to make a window stay on top and become transparent

Whilst looking for information on how to make a window stay on top using C#, I spotted some odd solutions on a number of other web sites. After looking through the Form properties in Visual Studio C# 2008 myself it turns out that it is really easy to make a window stay on top. I added a check box to by application and when it is ticked the window [...]