0
These days I posted the algorithm of this address below here because I was having problems to pop and remove was solved so far. Destamping Dynamic Stack
But as I was reviewing the code and therefore leaving them better I decided to put a for so that the user does not keep typing 1 in the menu to enter the numbers, then he would do the insertion according to the size of the vector:
So I did it below:
   if(op == 1)
    {
     for(i=0;i<=9;i++)
     {
      std::cout << "\n\tINSIRA NUMERO "<<i+1<<" NA PILHA: ";
       pilha *novo = new pilha();
       std::cin >> novo->num[i];
       novo->prox = topo;
       topo = novo;
      std::cout << "\n\tNUMERO "<<novo->num[i]<<" INSERIDO COM SUCESSO!!!";
     }
    }
But when I type 2 it returns everything zero. what I did wrong?
   if(op == 2)
    {
     i++; 
     if(topo == NULL)std::cout << "\n\tPILHA VAZIA!!!";
     else
      {
       std::cout << "\n\tPILHA COMPLETA: ";
       aux = topo;
       while(aux != NULL)
       {
        std::cout << aux->num[i] << " ";
        aux = aux->prox;
       }
      }
    }
						
How the structure/class has been defined
pilha?– Isac
is the same link algorithm that I put here only changed the int value in a; to int in a[10];
– dark777
i switched to a[10]; in mine here at base is the same algorithm ...
– dark777
If each stack element now has a vector with 10 numbers it is necessary to show them all in each iteration of its
while, starting from 0 to 9. As has just shows a number per stack element.– Isac
then I tried to do while(aux->num[i] <=10) but errors
– dark777
But he’s trying to insert several elements into the stack in a row
foris this ? Because to do this with the code you have does not need the vector that ends up complicating (although also give to do)– Isac
then I tried to do this without using vector, as it was I would have to access the menu if I wanted to insert 10 elements then I should choose 1 and then insert, and when doing this gave segmentation failure without defining one as vector..
– dark777