Only Correct answer will be rate. (12 pts) Write a function called reverseString
ID: 3732522 • Letter: O
Question
Only Correct answer will be rate.
(12 pts) Write a function called reverseString (), which uses a Stack to reverse a C string (char). The string that is to be reversed is passed in as a parameter. The function should reverse the characters in the string (i.e. "cat" becomes "tac") and return a pointer to the reversed string. A second string or array should NOT be used to reverse or store the characters. The Stack supports the following member functions: bool push (char c)i // adds c to the top of the stack bool Pop char // removes the character at top of stack and // parameter c bool isEmpty returns true if stack is empty; false otherwise The function header and Stack object instantiation has been supplied for you below: char reversestring (char *pstr) Stack theStack;Explanation / Answer
#define max 100;
int top;
Char [] stack[max],reverseStack[max];
bool push(char *pStr){
if (top==max-1)
{printed ("Stack is full"); return false;
}else {stack[++top]=*pStr;ret return true;}
}
bool pop(char &pStr)
{ stack[---top];
char * reverseString (char *pStr)
{ If(top==max-1)
printed("no data to reverse");return null;}
else
{
for(int i=0; i<=strlen(*pStr);i++)
{
reverseStack[strlen(*pStr)-i]=stack[i];
} return pStr;}
main(){
Char[] *str="abcd";
int length= strlen(*str);
int i=0;
for(i=0;i<=length;i++)
{
push(*str);
}
reverseString (*str);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.