/* * === FUNCTION ====================================================================== * Name: Insertar * Description: Inserta un entero positivo en el arbol * ===================================================================================== */ void Insertar(Arbol a, int elem, char *camino) { char *siguiente = (char*)getCabeza(camino); char *resto = (char*)getCola(camino); if (strcmp(siguiente,"I")==0){ if (a->izq==NULL){ a->izq=nuevoArbol(); } Insertar(a->izq,elem,resto); } if (strcmp(siguiente,"D")==0 ) { if (a->der==NULL){ a->der=nuevoArbol(); } Insertar(a->der,elem,resto); } if (strcmp(siguiente,"")==0) { if (a->Elem==-1){ a->Elem=elem; }else{ a->Elem=-1; } } }
int main() { Lista lista = NULL; pNodo p; Insertar(&lista, 20); printf("%p,%d", lista->siguiente, lista->valor); getchar(); Insertar(&lista, 10); Insertar(&lista, 40); Insertar(&lista, 30); MostrarLista(lista); getchar(); Borrar(&lista, 10); Borrar(&lista, 15); Borrar(&lista, 45); Borrar(&lista, 30); Borrar(&lista, 40); MostrarLista(lista); BorrarLista(&lista); return 0; }
//Inserta un nodo en el árbol binario void Insertar(tABB *arbol, tValor *valor){ tABB aux; aux=*arbol; if(!(*arbol)) { *arbol = valor; } else{ if((valor->frecuencia)<(aux->frecuencia)) Insertar(&aux->hijoIzquierdo, valor); if((valor->frecuencia)>(aux->frecuencia)) Insertar(&aux->hijoDerecho, valor); } }
main() { PtrLista PtrInicio=NULL; char Dato; Dato='c'; Insertar(&PtrInicio,Dato); Dato='w'; Insertar(&PtrInicio,Dato); Dato='b'; Insertar(&PtrInicio,Dato); ImprimirLista(PtrInicio); Eliminar(&PtrInicio); ImprimirLista(PtrInicio); Contador(PtrInicio); getche(); }
void Insertar(ptrNodo *a,int dato) { if(*a==NULL) { *a=(Nodo *)malloc(sizeof(Nodo)); (*a)->clave=dato; (*a)->der =NULL; (*a)->izq =NULL; } else if((*a)->clave<dato) Insertar(&(*a)->der,dato); else if((*a)->clave>dato) Insertar(&(*a)->izq,dato); }
void menu() { ptrNodo raiz=NULL; int opcion = 0, valor = 0; do { system("cls"); printf("[1] Ingresar numero\n"); printf("[2] Recorrido pre-orden\n"); printf("[3] Recorrido in-orden\n"); printf("[4] Recorrido post-orden\n"); printf("[5] Salir\n\n"); printf("\t\tIngrese su opcion: [ ]\b\b"); scanf("%d",&opcion); switch(opcion) { case 1: system("cls"); printf("Ingresa el valor: "); scanf("%d",&valor); Insertar(&raiz,valor); system("pause"); break; case 2: system("cls"); preorden(raiz); system("pause"); break; case 3: system("cls"); inorden(raiz); system("pause"); break; case 4: system("cls"); postorden(raiz); system("pause"); break; case 5: system("cls"); printf("Salida\n"); break; default: system("cls"); printf("error\n"); system("pause"); break; } }while(opcion != 5); }
int main () { Pila p; int x; int Aux; CrearPila(&p); scanf("%d", &x); Insertar (&p, x); printf("%d \n", cima(p)); // eliminando el elemento de la cima x y deja la pila vacia// if (!PilaVacia(p)) Aux = Quitar(&p); printf("%d \n",Aux); LimpiarPila(&p); return 0; }
void main() { textcolor(WHITE); textbackground(BLUE); clrscr(); char t; cuadro(1,80,1,6,177); cuadro(1,80,22,24,178); titulo(); do{ t=getch(); switch(t) { case 72://72 { if (f>10) {f--;} else {gotoxy(c-3,f);cprintf(" "); f=13;} //cambiar si se agregan mas opciones break; } case 80://80 { if (f<13)//cambiar si se agregan mas opciones {f++;} else {gotoxy(c-3,f);cprintf(" "); f=10;} break; } default: { /*gotoxy(21,14);printf(" Comando invalido"); delay(1000); gotoxy(21,14);printf(" ");*/ break; } } if ((t==13)&& (f==10)) { gotoxy(10,23);cprintf(" Insertar "); delay(1000); gotoxy(10,23);cprintf(" "); Insertar(); titulo(); } if ((t==13)&& (f==11)) { gotoxy(10,23);cprintf(" Sacar "); delay(1000); gotoxy(10,23);cprintf(" "); clrpart(); gotoxy(10,10);printf("1-Sacar por Pila"); gotoxy(10,11); printf("2-Sacar por Cola"); gotoxy(10,13);printf("opcion: "); gotoxy(18,13);scanf("%d",&op); if (op==1) { SacarPila(); } else if (op==2) { SacarCola(); } else { gotoxy(21,14);printf(" Comando invalido"); delay(1000); gotoxy(21,14);printf(" "); } op=0; titulo(); } if ((t==13)&& (f==12)) { gotoxy(10,23);cprintf(" Mostrar "); delay(1000); gotoxy(10,23);cprintf(" "); clrpart(); gotoxy(10,10);printf("1-Mostrar por Pila"); gotoxy(10,11); printf("2-Mostrar por Cola"); gotoxy(10,13);printf("opcion: "); gotoxy(18,13);scanf("%d",&op); if (op==1) { MostrarPila(); } else if (op==2) { MostrarCola(); } else { gotoxy(21,14);printf(" Comando invalido"); delay(1000); gotoxy(21,14);printf(" "); } op=0; titulo(); } if ((t==13)&& (f==13)) { gotoxy(10,23);cprintf(" saliendo "); delay(1000); gotoxy(10,23);cprintf(" "); t=27; } /*if ((t==13)&& (f==13)) { gotoxy(10,23);cprintf(" 5 opcion "); delay(1000); gotoxy(10,23);cprintf(" "); titulo(); } if ((t==13)&& (f==14)) { gotoxy(10,23);cprintf(" saliendo... "); delay(1000); gotoxy(10,23);cprintf(" "); }*/ textcolor(YELLOW); gotoxy(c-3,f); cprintf("->"); textcolor(WHITE); gotoxy(c-3,f-1);cprintf(" "); gotoxy(c-3,f+1);cprintf(" "); }while(t!=27); }
Operadores(){ InicioOperadores= 0; InicioFunciones= 0; Insertar("^",80,81,BINARIO); Insertar("SIN",80,81,UNITARIO); Insertar("COS",80,81,UNITARIO); Insertar("TAN",80,81,UNITARIO); Insertar("NOT",80,81,UNITARIO); Insertar("SINH",80,81,UNITARIO); Insertar("COSH",80,81,UNITARIO); Insertar("TANH",80,81,UNITARIO); Insertar("ASIN",80,81,UNITARIO); Insertar("ACOS",80,81,UNITARIO); Insertar("ATAN",80,81,UNITARIO); Insertar("TRUNC",80,81,UNITARIO); Insertar("ROUND",80,81,UNITARIO); Insertar("ABS",80,81,UNITARIO); Insertar("SQRT",80,81,UNITARIO); Insertar("RANDOM",80,81,UNITARIO); Insertar("LEN",80,81,UNITARIO); Insertar("LN",80,81,UNITARIO); Insertar("LOG",80,81,UNITARIO); Insertar("EXP",80,81,UNITARIO); Insertar("MOD",70,70,BINARIO); Insertar("*",70,70,BINARIO); Insertar("/",70,70,BINARIO); Insertar("+",60,60,BINARIO); Insertar("-",60,60,BINARIO); Insertar("<",50,50,BINARIO); Insertar(">",50,50,BINARIO); Insertar(">=",50,50,BINARIO); Insertar("<=",50,50,BINARIO); Insertar("=",40,40,BINARIO); Insertar("!=",40,40,BINARIO); Insertar("AND",20,20,BINARIO); Insertar("NAND",20,20,BINARIO); Insertar("OR",10,10,BINARIO); Insertar("NOR",20,20,BINARIO); Insertar("XOR",10,10,BINARIO); Insertar("XNOR",10,10,BINARIO); Insertar("(",0,100,BINARIO); Insertar(")",-1,-1,BINARIO); Insertar(",",-1,-1,BINARIO); Insertar("SUBSTRING"); }