palindrome..

how can i increment this??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  //---------------------------------------------------------------------
// Provides a method to test whether a string is a palindrome.
// Non letters are skipped.
//---------------------------------------------------------------------
class BoundedStack
{
    char* ptr;
public:
    char top(void)
    {

    }
    void push(char c)
    {

    }
    void pop(void)
    {

    }
};

class BoundedQueue
{
    char* ptr;
public:
    void enqueue(char c)
    {

    }
    char dequeue(void)
    {

    }
};

class Palindrome
{
    public:
    bool isLetter(char c)
    {

    }

    char toLowerCase(char c)
    {

    }

    bool testPalindrome(string candidate)
    // Returns true if candidate is a palindrome, false otherwise.
    {
        char ch;                   // current candidate character being processed
        int stringLength;          // length of candidate string
        int numLetters;            // number of letter characters in candidate string
        int charCount;             // number of characters checked so far

        char fromStack;            // current character popped from stack
        char fromQueue;            // current character dequeued from queue
        bool stillPalindrome;   // true as long as the string might still be a palindrome


        // initialize variables and structures
        stringLength = candidate.length();

        BoundedStack myStack(stringLength);   // holds non blank string characters
        BoundedQueue myQueue(stringLength);   // also holds non blank string characters

        numLetters = 0;

        // obtain and handle characters
        for (int i = 0; i < stringLength; i++)
        {
          ch = candidate[i];
          if (isLetter(ch))
          {
            numLetters++;
            ch = toLowerCase(ch);
            myStack.push(ch);
            myQueue.enqueue(ch);
          }
        }

        // determine if palindrome
        stillPalindrome = true;
        charCount = 0;
        while (stillPalindrome && (charCount < numLetters))
        {
          fromStack = myStack.top(); myStack.pop();
          fromQueue = myQueue.dequeue();
          if (fromStack != fromQueue)
            stillPalindrome = false;
          charCount++;
        }

        // return result
        return stillPalindrome;
    }
};

int main(){
	Palindrome p;
	string str;
	getline(cin,str);
    bool status = p.testPalindrome(str);

    if(status) cout<<"The string: "<<str<<", is a Palindrome."<<endl;
    else cout<<"The string: "<<str<<", is NOT a Palindrome."<<endl;

	return 0;
}
Topic archived. No new replies allowed.