Monthly Archives: October 2009

Reversing a Linked List

A very common interview question is to reverse a linked list without using recursion. If you’ve never done it before, this one can be challenging, especially if you don’t think visually.

The basic idea here is to keep a pointer to

  1. The previous node so that you don’t lose what you’re going to point the current node’s next pointer at.
  2. The current node.
  3. The next node, so that when you point the current node’s next pointer at the previous node, you don’t lose the reference to move on to next.

From there, after pointing the current node’s next pointer to the previous node, you just ‘inchworm’ your way forward until you’ve hit all nodes. At the end repoint the head to be where you’re at.

Here’s some code:

public void reverse() {

	if(this.head == null || this.head.next == null) {
		return;
	}

	Node previous = null;
	Node current = this.head;
	Node next = this.head.next;

	while(next != null) {

		current.next = previous;

		previous = current;
		current = next;
		next = current.next;

	}

	current.next = previous;
	this.head = current;

}

Coffee and See Plus Plus

Do you remember the first time you had coffee? A lot of people relate their first experience with coffee as a bad one. It’s common to hear people say that coffee is an acquired taste. For me this is untrue. I’ve always loved coffee from my very first taste, but I understand why people say it, and I want to relate that idea to C++ for a minute. C++ is a language that by more modern language standards is archaic, but it’s still arguably quite important to learn so that you understand manual memory management and how other languages are implemented.

Ok, so lets say you dive into C++ because you’re interested in knowing everything there is to know about programming. You discover it’s like your coffee experience; It’s bitter, it smells funny, and gives you jitters, but you keep on sipping it because you know it will give you benefits. Depending on your mileage, you might fast forward 6 months and find yourself practically hooking it up to your arm with an IV needle. Now that you feel comfortable with it and the knowledge it gave you, you’re ready to move on to new things. You’re satisfied that you used it as a learning tool, but are you really done with it? No; you’ll find that it’s still extremely pervasive in many areas of our industry.

And in that sense, it’s more like cocaine than coffee.

The gaming industry, or any industry that possesses an interest in high-performance computing applications, is addicted to C++. Regardless of how far managed code and garbage collection has come, they cling to it, because it’s got a lot of momentum attached to it. “JUST ONE MORE HIT MAN, JUST ONE MORE HIT”. I sympathize on the one hand because C++ ought to be mandatory learning material for computer science students (because it does teach you about how things work under the covers), but at the same time haven’t we come far enough with the performance of other languages that we can just go ahead and take C++ out back of the shed?

Politics, Networking, and Attracting Developers


“When a programmer complains about “politics”, they mean—very precisely—any situation in which personal considerations outweigh technical considerations. Nothing is more infuriating than when a developer is told to use a certain programming language, not the best one for the task at hand, because the boss likes it. Nothing is more maddening than when people are promoted because of their ability to network rather than being promoted strictly on merit. Nothing is more aggravating to a developer than being forced to do something that is technically inferior because someone higher than them in the organization, or someone better-connected, insists on it.”

“You do have to pay competitively, but all said, of all the things that programmers look at in deciding where to work, as long as the salaries are basically fair, they will be surprisingly low on their list of considerations, and offering high salaries is a surprisingly ineffective tool in overcoming problems like the fact that programmers get 15″ monitors and salespeople yell at them all the time and the job involves making nuclear weapons out of baby seals.”

Source: Field Guide to Developers