Write A Program In C++ To Determine If Numbers Are Palindromes Using A Stack-Based Method For Testing.

Need help with similar Computer Science questions?

Ask A Question

Question: Write A Program In C++ To Determine If Numbers Are Palindromes Using A Stack-Based Method For Testing.

Viewed 59
Objective: Write a program to determine if numbers are palindromes using a stack-based method for testing. Program Description: Write a program that determines if a number is a palindrome. Recall that palindromes are strings (sequences of characters) that read the same forward or backward after punctuation and spacing is removed. The stack sample code that we discussed in class is a good starting point for this assignment. Note that the stack you will need to use is character-based. Consider converting the integer stack code to characters. Requirements: In addition to the functional description above, your solution also: • Must have the stack implemented as a linked list (class optional). You may use (extend) any code covered in lecture. You may not use the STL (Standard Template Library). • Must have the logic/implementation in a separate file from the stack implementation (an application file). • Must organize the source code files in accordance with the class standards. In other words, separate class declaration files (ADT header file), class implementation files (ADT implementation file), and application file.
More Instructions
/* link.cpp * * Class for a sorted linked list of integers. */ #ifdef NOT_USING_CC_WHATEVER_ITS_PREDEF_IS #include <bool.h> #endif #include <iostream.h> #include "link.h" // Add an item to the FRONT of the list void LinkedList::AddNode( int x ) { nodeptr n; // allocate new node n = new node; n->info = x; count++; if( start == NULL ) { start = n; n->next = NULL; } else { nodeptr tmp = start; n->next = tmp; start = n; } } //\end{verbatim} \lecpb \begin{verbatim} void LinkedList::DeleteNode( int x ) { nodeptr prev, curr; curr = start; while( curr != NULL && x > curr->info ) { prev = curr; curr = curr->next; } if( x == curr->info ) { if( curr == start ) start = start->next; else prev->next = curr->next; delete curr; count--; } } //\end{verbatim} \lecpb \begin{verbatim} int LinkedList::FirstNode() { return start->info; } void LinkedList::PrintNodes() { nodeptr p = start; while( p != NULL ) { cout << p->info << endl; p = p->next; } } //\end{verbatim} \lecpb \begin{verbatim} #ifdef NOT_USING_CC_WHATEVER_ITS_PREDEF_IS bool LinkedList::IsInList(int x) #else int LinkedList::IsInList(int x) #endif { nodeptr p = start; while( p != NULL && x > p->info ) p = p->next; return (x == p->info); } int LinkedList::Size() { return count; } /* link.h */ // This is a class for a linked list of integers. #ifndef LINK_H #define LINK_H #ifdef NOT_USING_CC_WHATEVER_ITS_PREDEF_IS #include <bool.h> #endif #include <iostream.h> class LinkedList { private: struct node { int info; node * next; }; typedef node * nodeptr; nodeptr start; int count; //\end{verbatim} \lecpb \begin{verbatim} public: // Constructor LinkedList() { start = NULL; count = 0; } // Destructor ~LinkedList() { nodeptr p = start, n; while (p != NULL) { n = p; p = p->next; delete n; } } // Add a node onto the front of the linked list. void AddNode(int x); // Delete the first node found with the value x, if one exists. void DeleteNode(int x); // Return the first node found in the list int FirstNode(); // Output the values in the nodes, one integer per line. void PrintNodes(); // Return true if there in a node in the list with the value x. //bool IsInList(int x); int IsInList(int x); // Return a count of the number of nodes in the list. int Size(); }; #endif
Answers 0

No answers posted

Post your Answer - free or at a fee

Login to your tutor account to post an answer

Posting a free answer earns you +20 points.


Ask a question for free and get answers to get Computer Science assignment help with a similar task to this question.