Linked Lists Youtube Tutorials

Video

When I was studying, I came across a particularly useful set of videos on Linked Lists. Youtube tutorials are great for learning programming because the poster usually adds a link to code to play around with and learn from, and you can pause and rewind if there’s ever a concept you want to go back and review.

Gwendolyn Potter and The Return of CMenuItem

The return of the text of Label to be specific.. As I was working on CMenuItem, I strangely found myself having the most problems with this simple task, within the const char* Text(); method. Eventually I realized that of course! Returning the text of CLabel is simply returning the data. So this is the code I ended up with:

const char* CMenuItem ::Text(){
return (const char*)Label.data();
}

Very simple task, yet strangely difficult to come with up a solution for. Typical C++!

Priority Queues

As said in my last post, I found the idea of a priority queue to be intriguing, and decided to do some more research in the matter. I was actually surprised to find that this is an important part of queues in c++, and not just something Fardad decided to include for fun (not that he would do that of course! everything is always for a reason when it comes to his teaching style.)

There’s even a page explaining the concept here:

http://www.cplusplus.com/reference/queue/priority_queue/

Here is one nice example of a priority queue that someone wrote: http://www.codingfriends.com/index.php/2010/06/21/priority-queues-part-1/

I find it funny that they mention it being similar to an ER queue in a hospital.

Here’s a small chunk of their code (disclaimer: not written by me! see link to codingfriends for more)

// find the highest chunk of space where newElem could be placed into the best chunk
PQueue::chunkSpace* PQueue::findHighestChunk(chunkSpace *&space, int newElem)
{
	if (space == NULL) return NULL;
	// found the previous chunk to insert into
	if (space->values[space->lastBlock-1] > newElem && space->lastBlock > 0)
			return space;
	else
	{
		chunkSpace *retPlace = findHighestChunk(space->nextBlock, newElem);
		if (retPlace == NULL)
			return space;
		else
			return retPlace;
	}