In: Computer Science
Translate the following C++ code to Pseudocode:
int main()
{
stack<char> stk,stk2;
int length =0,ele;
while(cin>>ele)
{
stk.push(ele);
length++;
}
if(length%2)
stk.pop();
for (int i=0;i<length/2;i++)
{
ele=stk.top();
stk.pop();
stk2.push(ele);
}
int flag=1;
for(int i=0;i<length/2;i++)
{
if(stk.top()==stk2.top())
{
stk.pop();stk2.pop();
}
else
{
flag=1; break;
}
}
if(flag==1) cout<<"NOT palindrome";
else
cout<<"palindrome";
}
Palindrome program in C++
A palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers.
Palindrome number algorithm
Pseudo code is a term which is often used in programming and algorithm based fields. It is a methodology that allows the programmer to represent the implementation of an algorithm. Simply, we can say that it’s the cooked up representation of an algorithm. Often at times, algorithms are represented with the help of pseudo codes as they can be interpreted by programmers no matter what their programming background or knowledge is. Pseudo code, as the name suggests, is a false code or a representation of code which can be understood by even a layman with some school level programming knowledge.
Algorithm: It’s an organized logical sequence of the actions or the approach towards a particular problem. A programmer implements an algorithm to solve a problem. Algorithms are expressed using natural verbal but somewhat technical annotations.
Pseudo code: It’s simply an implementation of an algorithm in the form of annotations and informative text written in plain English. It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the computer.
pseudo code for palindrome algorithm :