Monthly Archives: April 2021

C++ || Simple Palindrome Checker Using A Stack & Queue Using C++

The following is a program which demonstrates how to use a stack and a queue to test for a palindrome using C++.

The program demonstrated on this page is an updated version of a previous program of the same type. This program is great practice for understanding how the two data structures work.


Template Classes - What Are They?
LIFO - Last In First Out
FIFO - First In First Out

1. Overview

This program first asks the user to enter in text which they wish to compare for similarity. The data is then saved into the system using the “enqueue” and “push” functions available within the queue and stack classes. After the data is obtained, a while loop is used to iterate through both classes, checking to see if the characters at each location within both classes are the same. If the text within both classes are the same, it is a palindrome.

2. Palindrome Checker

The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output:

====== RUN 1 ======

Enter in some text to see if its a palindrome: StEP on No pETS

StEP on No pETS is a palindrome!

====== RUN 2 ======

Enter in some text to see if its a palindrome: Hello World

Hello World is NOT a palindrome..

====== RUN 3 ======

Enter in some text to see if its a palindrome: Kenneth, Jennifer, Lynn, Sole

Kenneth, Jennifer, Lynn, Sole is NOT a palindrome..