Good morning. I have a doubt with a c ++ code, in which I use stacks and tails, basically I have to build a stack and a dictionary, both of characters, for each character belonging to the stack to verify if it is in the dictionary, and if the answer is positive the character must be entered in a queue (initially empty), otherwise it must be discarded.
This is what I have:
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main ()
{
stack <string> pila;
pila.push("Palabra1");
pila.push("Palabra2");
pila.push("Palabra3");
pila.push("Palabra4");
cout << "Hay en total " << pila.size () << " palabras en el diccionario" << endl;
cout<<endl;
cout << "Palabras en el diccionario: ";
while(!pila.empty()) {
cout <<endl<< pila.top() << endl;
pila.pop();
}
string diccionario[] = {"Palabra1", "Palabra2", "Palabra3", "Palabra4"};
cout<<"Verificando si las palabras de la pila se encuentran en el diccionario"<<endl;
cout<<"Opciones: Palabra1, Palabra2, Palabra3, Palabra4"<<endl;
cout<<endl;
//Aqui deberia hacer la comparacion entre la pila y el diccionario para luego agregar los valores a la cola
queue <string> cola;
//estas serian las sentencias si se encontrara la palbra en el diccionario
cout<<"La palabra introducida se encuentra en el diccionario"<<endl;
cout<<"Se procedera a introducirla en la cola"<<endl;
cola.push("Palabra1"); } else {
cout<<"La palabra no se encuentra en el diccionario por lo tanto no se agregara a la cola"<<endl;}
while(!cola.empty()) {
cout <<endl<< cola.front() << endl;
cola.pop(); }
system("pause");
}
My doubt would be like comparing the stack and the "dictionary" that I do not know if it would be useful to create it as an array or as another stack or queue, since they do not specify if the dictionary should be a stack, queue or array. Thank you very much for your answers