-1
EX: x = "ABABBA" and y= ABBABA
I’ve done the class Pilha
, with the methods, but I am doubtful how to implement.
package questao02;
public class Pilha<T> {
T[]arrayelem;
int topo;
int index = 0;
public Pilha(int max){
this.arrayelem = (T[]) new Object[max];
this.topo = -1;
}
public boolean estaCheia(){
return this.topo == this.arrayelem.length-1;
}
public boolean estaVazia(){
return this.topo == -1;
}
public boolean inserir(T elem){
if(!this.estaCheia()){
this.arrayelem[++ this.topo] = elem;
return true;
}
return false;
}
public T remover(){
if(!this.estaVazia()){
T aux = this.arrayelem[this.topo];
this.topo--;
return aux;
}
return null;
}
}
I wanted to understand the logic, whether it’s a slump or not.
You can’t understand what you want to do, but the code is necessary. Check the help center for items in the section asking: https://answall.com/help
– mari
I’ve already modified the code
– user160874
Palindrome means that the string backwards is equal to the string itself. But in your case, x and y are not palindromes - in fact one is the inverse of the other. You want to check if they are palindromes or if one is inverse of the other?
– hkotsubo
I want to check if one is the reverse of the other... I thought they were Palindromos,but they’re not,
– user160874
If it’s an exercise and you’re forced to use stack, it’s simple: Pop the x characters, then go pop and compare to the y characters. But if you don’t have to stack, you can reverse x and compare with y.
– hkotsubo
I will have to use stack... Then in case,I would stack everything before,inside a loop,and then I would pop check. That would be it?
– user160874
Basically this :-)
– hkotsubo