Welcome to the third and final segment on my implementation of Speller from problem set 5 of CS50. Before we begin, make sure that you have read and understand Part 1 and Part 2 of this problem set.  This will be a short post, since I am only going to cover the last two functions for this problem set. These functions include size and unload. So, let’s dig in.

The implementation of size is very straightforward. Remember, when we implemented the load function, that we made sure to keep track of the size of the dictionary by incrementing the variable word_count. The reasoning for this was to make this function easier on us. We simply just return the word_count variable.

Unload is slightly more complicated. However, you will notice a similarity between the load and unload functions. Remember, when we implemented the load function, we never freed the memory. This is where the unload function comes into play. The function starts with a for loop that is going to iterate over every node in the linked list that is our dictionary. While our node cursor is not null (which would indicate that we have reached the end of the list) we move the cursor to the next node and free the previous node from memory. This iteration will continue until our entire list has been freed from memory.

As promised, this was a short post. I hope that this 3 part series helped you work through this last problem set involving the C programming language. Next week, we will begin diving into web programming by using Python, HTML, and CSS. Please comment below if you have any questions, and don’t forget to share this post by clicking the buttons below. As always…Happy Programming!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s