Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Palindrome Template Function The focus of this assignment is on using the built-in list container from the STL library, and on using iterators to

A Palindrome Template Function

The focus of this assignment is on using the built-in list container from the STL library, and on using iterators to process and traverse the list. You will be using templates for this assignment.

The list container from the STL library is implemented as a doubly linked list,. where each node in the list has both a previous pointer (prev) that points to the previous node in the list, and a next pointer that points to the next node in the list. Because of this, list objects can be traversed in both direction.

1. Write a templated function named palindrome that takes a list parameter and returns true or false according to whether the list does or does not read the same forward as backward (e.g., a list containing 1, 2, 3, 2, 1 is a palindrome, but a list containing 1, 2, 3, 4 is not). Note that because the function is templated, only ONE palindrome function is needed to support any type (e.g., int, char, string, bool, double, etc.). This function should use iterators to process and traverse the list.

2. Write a templated function named printlist that takes a list parameter and prints out the contents of the list. Note that because the function is templated, only ONE printlist function is needed to support any type (e.g., int, char, string, bool, double, etc.). This function should use an iterator to process and traverse the list.

Application code:

#include

#include

#include

using namespace std;

int main()

{

list int_list;

list char_list;

list bool_list;

int x = 0;

for (int i = 75; i >= 65; --i)

{

int_list.push_back(i);

char_list.push_back(static_cast (i + x));

if (i <= 70)

x += 2;

}

bool_list.push_back(true);

bool_list.push_back(false);

bool_list.push_back(false);

bool_list.push_back(true);

printlist(int_list);

cout << (palindrome(int_list) ? " is " : " is not ") << "a palindrome ";

printlist(char_list);

cout << (palindrome(char_list) ? " is " : " is not ") << "a palindrome ";

printlist(bool_list);

cout << (palindrome(bool_list) ? " is " : " is not ") << "a palindrome ";

system("PAUSE");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago