![]() I have the program written, but there appears to be some logic error somewhere. This will be the reverse of the original. Check palindrome using LinkedList as queue and stack. Now, since the LAST character of the string is on top, you just need to pop until the stack is empty and store it in a string. So the resulting stack would look like this: TOP -> tset <- BOTTOM. ![]() Stack is a LIFO (Last in First out) data structure where data is removed from the top of the stack only. string s 'test' for i0 to s.length stack->push(si) This would push t->e->s->t from left to right. Data is inserted using push() operation and deleted using pop() operation. About Products For Teams Stack Overflow Public questions & answers Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers. Overview: Stack: Stack is a linear data structure used to store a collection of data. I have an assignment that requires me to take a string from the user and pass it into a stack and a queue, then use those two to compare the chars to determine if the string is a palindrome. I am using recursion to find out whether a string is a palindrome, while ignoring spaces and non letter characters. Also my code will return true if given an empty string as input. Note that 12bb cannot be made into a palindrome using only one character change, so your test case appears to not match your specifications of replacing only one letter. Public static void main(String args) throws disclosure: this is for an assignment, so please don't post actual code solutions! Output: cat using c: true axaa using x: true 12bb using b: false ca using c: true. Learn to check if a given string is palindrome string with simple java programs using stack, queue or simple loops. ![]() ![]() The following code seems to work (no more NZEC), but it ends up with time limit exceeded. ![]() Palindrome Java application illustrates the use of a stack.
Are you assigning a value to a function (pop ()) You have to build reverse from popping from the stack. The reason is that neither int neither long are big enough to store a given positive integer K of not more than 1000000 digits - 1000000 digits is well 10 1000000, while Long.MAX_VALUE is only 2 63-1. File: Palindrome.java // This program determines whether an input line is a. PDrome.pop ()reverse.charAt (i) is wrong. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |