You are not quite right.
The variables
stackChar
and
queueChar
don't have to be initialized. It is assumed that the values are assigned to them as you pop and dequeue data. Moreover, if you were right, it would have nothing to do with performance, rather if would mean defunct code, or, say, unreliable code, which results may depends on some random factors (such as different results for the execution under the debugger and without the debugger). This is not really the case. By the way, such issues are impossible in decent programming language (sorry, but no, I don't think C++ is decent, not even close, not even in terms of good low-level support) — the uninitialized variables either caught compilation errors, or the compiler figures out that this is not needed.
So, the summary: 1) the problem you pointed out is not a problem, 2) it would not be related to performance.
The better verdict on performance would be this: using just the array would be faster. The key here is: there is no need to use any data collection of the variable size. The user enter the test phrase at once, so your code could create the whole array at once, which removes all possible performance problems; there is no anything like reallocation; and in all other aspects, array would be the fastest. Overall, the quality of the code is… so-so…
Now, about the first part of your answer: "checking whether the given string is palindrome". It would be true if your intuitive expectation of what this code really does was true. In other works, the answer is good as soon as you don't say "strictly speaking".
But what is that code fragment, strictly speaking? Strictly speaking, this is… who knows what. Something uncertain. Why? Because there is no indication that
StackType
and
QueueType
really implement stack "the usual" generic (template) data structures "stack" and "queue", that the implementation is correct, that the functions you are using are what you expect, and so on. Strictly speaking, the name of a type or a template type carries no information on what it really does. The code is not shown, and the formulation of the problem says no word about what it is. Maybe I would not pick on that, but using the word "Type" in the name of type tells the tail; it does not look as an reasonable or even adequate developer's behavior. By the way, then names of standard C++ type implementing the stack and the queue are:
std::stack
and
std::queue
; they are the template classes:
std::stack,
queue — C++ Reference.
So, I would not trust much the software engineer who wrote "StackType" or "QueueType". :-)
—SA