Está en la página 1de 3

#include<iostream>

#include<conio.h>
#include<stdlib.h>
using namespace std;

struct Nodo {
int dato;
Nodo *siguiente;
};
void insertarCola(Nodo *&, Nodo *&, int);
bool cola_vacia(Nodo *);
void buscar();
void menu() {
cout << "\t\t::Menu::" << endl;
cout << "1.) Ingresar datos" << endl;
cout << "2.) Buscar datos" << endl;
cout << "3.) exit" << endl;
};

int main() {
Nodo *frente = NULL;
Nodo *fin = NULL;
char op;
int dato;
char opcion;

do {
menu();

switch (opcion) {
case 1:
cout << "\t\t Ingresando datos al systema" << endl;
do {
int dato;
cout << "Ingrese un numero: ";
cin >> dato;
insertarCola(frente, fin, dato);

cout << "\n";


cout << "Desea ungresar mas Datos S/N" << endl;
cin >> op;
} while (op == 'S' || op == 's');
cout << "\n";
break;
case 2:
cout << "\t\t Buscar Datos del sistema" << endl;
buscar();

break;
}

cout << "Desea ungresar mas Datos S/N" << endl;


cin >> opcion;
} while (opcion == 'y' || opcion == 'Y');
cout << "\n";
system("pause");
cout << "\n";
return 0;

void insertarCola(Nodo *&frente, Nodo *&fin, int n) {


Nodo *nuevo_nodo = new Nodo();

nuevo_nodo->dato = n;
nuevo_nodo->siguiente = NULL;

if (cola_vacia(frente)) {
frente = nuevo_nodo;
}
else {
fin->siguiente = nuevo_nodo;
}
fin = nuevo_nodo;
}
bool cola_vacia(Nodo *frente) {
if (frente == NULL) {
return true;
}
else {
return false;
}
//otra forma de comprobar si la cola esta bacia es esta
//return (frente == NULL) ? true : false;
}

void buscar() {
int fin = 0;
int frente = 0;

if (fin == NULL) {
cout << "la cola esta bacia"<<endl;
return;
}
else {
frente = fin;
bool encontrado = false;
int buscar_datos;
cout << "ingrese el dato a buscar::_";
cin >> buscar_datos;
while (!frente==NULL) {
if (buscar_datos == *&,frente->fin) {
cout << "dato encontrado" << endl;
encontrado = true;
break;
}
frente = *&,frente->siguiente;
}
if (encontrado == false) {
cout << "no se encontro el dato" << endl;
}
}

También podría gustarte