We will then compare it with correspondingĬharacters of input string. * Poping characters from stack returs the characters of input string * Push all characters of input String to Stack */ Removes top element from stack and decrement top index Structure defining Stack data structureĪdds an element to stack and then increment top index If we found a mismatch the input string is not a palindrome string otherwise palindrome string.Ĭ program to check a string is palindrome or not using a stack PERFORM 20 TIMES MOVE WORTTXT1 (LOP:1) TO B (20:LOO) SUBTRACT 1 FROM LOO ADD 1 TO LOP MOVE B TO WORTTXT2 (20:LOU) SUBTRACT 1 FROM LOU END-PERFORM. Remove (Pop) characters from stack one by one using a for loop and compare it with corresponding character of input string from beginning(traverse from index 0 to length-1). 1 my task is to reverse a string in cobol without using the reverse function. ![]() ![]() ![]() Using a for loop, traverse input string from index 0 to length-1 and push all characters in stack.Find the length of the input string using strlen function and store it in a integer variable "length".Algorithm to check palindrome string using stack
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |