Mixes of data structures

Sometimes it’s easier to solve a problem if you use a mix of data structures. For example, you can easily determine whether a sequence of characters is a palindrome if you use both a stack and a queue. Just add the characters of the sequence to each data structure, and then remove a character from each data structure one at a time and compare them. The sequence is a palindrome if and only if the characters are always the same.

Here is my C++ implementation of a palindrome checker.

Here is a Python implementation of a palindrome checker.

Both implementations are up at my GitHub.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s