Doubt in data structure Batteries

1

I have a question with exercise of batteries that I found, in this exercise, it looks for how many times a letter is repeated and also returns the number of letters that are in an even position.

I have several doubts, one of them is in this part:

What are you doing there?

while(!pila.empty()){
                             par=!par;//por cada letra pasa a ser impar, par
                             pila.pop();
                         }

What do you want to do with the instruction par=!par and then pila.pop(); ?

bool letrapar (char palabra[], char letra, stack_l_t<char> pila){
                     bool par=true;
                     int i=0;
                     int l=strlen(palabra);
                     while(i<l){
                        if(letra==palabra[i])
                            pila.push(palabra[i]);//meto las letras que busco en la pila, o eso entiendo

                        i++;
                     }
                     while(!pila.empty()){
                         par=!par;//por cada letra pasa a ser impar, par
                         pila.pop();
                     }
                    return par; 
                }
    
asked by AER 20.07.2017 в 22:06
source

1 answer

4

Nowhere is this exercise looking to see how many times a letter is repeated.

This exercise only uses a complicated method (with a stack, bah) to know if the number of letters the word has is odd or even a certain letter repeats an even or odd number of words times within the word.

while(i<l){
    if(letra==palabra[i])
        pila.push(palabra[i]);//meto las letras que busco en la pila, o eso entiendo
    i++;
}

The above code inserts only the letters that are the same as the letter it received per parameter into the stack.

par=!par as par is a variable booleana , causes the same to be transformed to its opposite, that is if true goes to false , and if it is false for a true

and pila.pop() , as I answered a while ago, remove the item from the stack that follows (which is always the first).

while(!pila.empty()){
    par=!par;//por cada letra pasa a ser impar, par
    pila.pop();
}

And this code, is removing from the stack and changing the value of par between true and false

    
answered by 20.07.2017 / 22:28
source