i have an assignment to check if the stack is palindrum (ex 1 2 3 4 3 2 1 is palindrum 1 2 3 4 5 3 2 1 is not)
i cant use the method isEmpty and i can use only another stack
so my question is how the hell i do that?
i thought to use the other stack like i transfere hlaf of the first stack to the other and then compare between them but it doesn't work beacuase i get out of order
so help me plz
What have you done so far? Break the problem down to the smallest pieces...you will have to compare the first half and the second half of the string (in reverse). How would you go about doing this? Placing each half in its own stack? Iterate over the first stack in reverse? Try and if you get stuck post some code with any errors or wierd behavior
i dont know when i get to the half thats my problem
i thought about what u say but the problem that i dont know when i get to the half and to the end of tha stack
Review the API's for String and Stack. Each has methods that will be useful, for example String.length() can let you know when you've reached the halfway point. This is what I mean by breaking the problem down...ask specific questions like 1) I need to know where the 'halfway point' in a string is...if I knew the length then I can get half the length (divide by 2)...then how do I get the length of the string? Once I have that, how can I loop over the string? How do I get the character at a specific position? Each of these can be answered using the links above as a reference. Ask one question at a time and build off of each.