This content is password protected. To view it please enter your password below:

Advertisements

 

Here is some text

A picture!

P1140405  More text here too

 

And some more text

Yay blogging

I am studying to take my insurance licensing exam for the second time :-p and I thought hey why not write some entries about the insurance stuff I learn.  Hopefully I may learn the material better if I try to summarize all the rules in my own words and make them a little bit more riveting for my readers.  Hopefully you all will learn something and not fall asleep :D.  Tune in tomorrow for the first post(s)!

I wrote this up in an email to myself a while ago but I figure I’ll post it up here too.  A very common programming interview question is how to reverse a singly linked list.  I’ve gotten this in two interviews and also in an algorithms problem set once.

Here are my solutions, both an iterative and a recursive approach.  I think I’ve tested both out pretty well  but please do let me know if you break either one 🙂 .  Also, I use a class called ZNode which is just an ordinary node class, just cooler because it has a “Z” in it.

Iterative:
basically go from head to end, reversing as you go by using 3 pointers to: theHead, revHead, and hold (actually the names are pretty arbitrary).  

//Iterative
        ZNode reverseIter(ZNode head)
	{
		ZNode theHead = head;
		if(theHead.getNext() == null)
		{
			return theHead;
		}
		ZNode revHead = theHead.getNext();
		ZNode hold = revHead;

		while(hold != null)
		{
			hold = hold.getNext();
			revHead.setNext(theHead);

			//set the next of the head of the list to null
			if(theHead == head)
			{
				theHead.setNext(null);
			}

			theHead = revHead;
			revHead = hold;
		}
		return theHead;

	}

Recursive:
Start at the head and keep going until you hit the end, then go backwards setting each node’s next field to its parent.  Each recursive call has the parameters: head, parent, and revHead (the head of the new reversed list) 

//Recursively
	ZNode reverse(ZNode head)
	{
		return reverseHelper(head,null,null);
	}

	ZNode reverseHelper(ZNode head, ZNode parent, ZNode revHead)
	{
		if(head.next == null)
		{
			head.setNext(parent);
			revHead = head;
			return revHead;
		}
		else
		{
			revHead = reverseHelper(head.getNext(),head, revHead);
			head.setNext(parent);
			return revHead;
		}
	}

 

Dialga on the Spear Pillar in 3D

Dialga on the Spear Pillar in 3D

 

 

I just caught Dialga, one of the main legendaries of Pokemon Diamond, with a Quick Ball (a pokeball that works well if used in the first 5 turns of battle) on the first turn without doing any damage to it!  It was like I just used a Master Ball.  Okay end of extremely dorky post.

Testing this out by posting this now since I just posted a bunch of things were I modified the publish date to a date in the past.  I might have to import them all again manually.

Pictures: http://picasaweb.google.com/ChrisWKwan/NewYork010609Fb?feat=directlink

  • 3 roommates had left room already when we woke up
  • Breakfast at Grand Central Station (almond pastry, Citrus Naked juice, Orangeade Snapple for bus ride home)
  • Walked with Nate to his bus stop
  • Nate leaves
  • Simon and Chris go to Columbus Circle
  • Look for CNN building but cannot find it
  • Go to the mall – very nice, two large statues of very large people
  • Interesting art gallery on 2nd floor – a picture of an xray of a tractor and a man riding it
  • Samsung Experience: screens under glass, camera overhead tracks the movements of your hands over the glass so you can navigate around a map of the city
  • Samsung store has nice coaches and displays
  • Cartoon network store
  • Train back to Penn Station to get on corner near Tick Tock diner for Bolt bus
  • Chris gets on the Bolt bus to go back home to Boston.
  • Chris is home!