Академический Документы
Профессиональный Документы
Культура Документы
INORDEN, POST-ORDEN
#include <iostream>
#include <cstdlib>
struct nodo{
int nro;
};
ABB crearNodo(int x)
nuevoNodo->nro = x;
nuevoNodo->izq = NULL;
nuevoNodo->der = NULL;
return nuevoNodo;
if(arbol==NULL)
arbol = crearNodo(x);
insertar(arbol->der, x);
if(arbol!=NULL)
preOrden(arbol->izq);
preOrden(arbol->der);
if(arbol!=NULL)
enOrden(arbol->izq);
enOrden(arbol->der);
if(arbol!=NULL)
postOrden(arbol->izq);
postOrden(arbol->der);
cout << arbol->nro << " ";
if(arbol==NULL)
return;
verArbol(arbol->der, n+1);
cout<<" ";
verArbol(arbol->izq, n+1);
int main()
cin >> n;
cout << " Numero del nodo " << i+1 << ": ";
cin >> x;
system("pause");
return 0;
}
AUTOMATA FINITO :
#include
<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdlib.h>
#define MAX 100
using namespace std;
// Generando estados
cout << "\n Cantidad de Estados: ";
cin >> numE;
for(int i=0; i<numE; i++){
E.push_back(i);
}
// Ingresando simbolos
cout << "\n Cantidad de Simbolos: "; cin >> numS;
cout << endl;
for(int i=0; i<numS; i++){
cout << "\t Simbolo " << i+1 << " : ";
cin >> c;
S.push_back(c);
}
sort(S.begin(),S.end()); // Ordenando simbolos
void menu(){
cout << "\n\t\t AUTOMATA FINITO DETERMINISTA\n\n";
cout << "\t 1. Ingresar Automata \n";
cout << "\t 2. Verificar palabra \n";
cout << "\t 3. Salir \n";
cout << "\t Ingrese opcion: ";
}
int i, k=0;
while(w.size()!=palabra.length()){
for(i=0; i<S.size(); i++){
if(palabra[k]==S[i]){
w.push_back(i);
}
}
k++;
}
}
/* Funcion Principal
--------------------------------------------------------------*/
int main()
{
vector<int> Estados;
vector<char> Simbolos;
int Transiciones[MAX][MAX];
int q0; // Estado inicial
vector<int>qf; // Estados finales
vector<int>w;
bool AutomataIngresado = false; // Aun no se ha ingresado automata
do{
menu(); cin>>op;
switch(op){
case 1:
Estados.clear();
Simbolos.clear();
qf.clear();
AutomataIngresado = true;
break;
case 2:
if(AutomataIngresado){
string palabra;
w.clear();
bool EstadoVerificacion = false;
cout << "\n Ingrese palabra: ";
cin>> palabra;
if(EstadoVerificacion){
cout << "\n\t Palabra aceptada \n\n";
}
else{
cout << "\n\t Palabra no aceptada \n\n";
}
}
else{
cout << "\n Automata no ingresado..! \n";
}
break;
case 3:
exit(0);
default:
cout << "\n\tOpcion incorrecta..!\n";
}
}while(op!=3);
}