Technology, life, programming, travel and money.

Posts Tagged ‘source code’

DOS: Get the directory name from a file path

DOS: Get the directory name from a file path

If you need to write a DOS batch file that takes a file path as an input parameter and needs to do something to other files in the same directory as the input file then you’ll find there is no easy way to get the file’s directory name into a variable. You could pass in the directory name as a separate parameter but that seems like [...]

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 [...]

AdSense Injection WordPress plugin tweaks

Update 7th December 2010: Use the new Ad Injection plugin for WordPress instead as it will do what these tweaks do, and more. On this blog I use the Adsense Injection plugin to automatically add Google's targeted AdSense adverts to my posts. The plugin is excellent and has helped to make more money for this site but there are a few tweaks that [...]

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++ [...]

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 [...]

 Page 1 of 2  1  2 »