Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct abb{
- char legajo[10];
- int hsext;
- struct abb *der;
- struct abb *izq;
- }tarbol;
- struct nodo{
- char leg[10];
- int hsext;
- struct nodo *sig;
- }*inicio, *actual;
- void cargaABB(tarbol **A, char l[],int n){
- if (*A==NULL){
- *A=malloc(sizeof(tarbol));
- (*A)->hsext=n;
- strcpy((*A)->legajo,l);
- (*A)->der=NULL;
- (*A)->izq=NULL;
- }
- else{
- if (strcmp((*A)->legajo,l)<0){
- cargaABB(&(*A)->izq,l,n);
- }
- else
- cargaABB(&(*A)->der,l,n);
- }
- }
- void imprimedesc(tarbol *A){
- if (A!=NULL){
- imprimedesc(A->der);
- printf("%s %d\n",A->legajo,A->hsext);
- /* push a la pila */
- push(A->hsext);
- imprimedesc(A->izq);
- }
- }
- typedef struct licirc{
- char leg[5];
- int hextr;
- struct licirc *sig;
- }tcirc;
- tcirc *generaNODOCIR(char l[], int n){
- tcirc *aux;
- aux=malloc(sizeof(tcirc));
- strcpy(aux->leg,l);
- aux->hextr=n;
- return aux;
- }
- void cargacircORD(tcirc **LC, char l[], int n){
- tcirc *aux,*ant,*act;
- aux=generaNODOCIR(l,n);
- if (*LC==NULL){
- aux->sig=aux;
- *LC=aux;
- }
- else{
- if (strcmp((*LC)->leg,aux->leg)>0){
- act=*LC;
- while(act->sig!=*LC){
- act=act->sig;
- }
- aux->sig=*LC;
- act->sig=aux;
- *LC=aux;
- }
- else{
- ant=*LC;
- act=ant->sig;
- while(act!=*LC && strcmp(act->leg,aux->leg)<0){
- ant=act;
- act=act->sig;
- }
- ant->sig=aux;
- aux->sig=act;
- }
- }
- }
- int siexsite(tcirc *LC, char l[]){
- tcirc *aux;
- if (LC!=NULL){
- aux=LC;
- while(aux->sig!=LC && strcmp(aux->leg,l)!=0){
- aux=aux->sig;
- }
- if (strcmp(aux->leg,l)==0){
- return 1;
- }
- else
- return 0;
- }
- else
- return 0;
- }
- // genera Lcirc desdee un arbol
- void generalistacirc(tarbol *A, tcirc **LC){
- tcirc *aux;
- if (A!=NULL){
- generalistacirc(A->izq,&(*LC));
- generalistacirc(A->der,&(*LC));
- if (!siexsite(*LC,A->legajo)){
- cargacircORD(&(*LC),A->legajo,A->hsext);
- }
- else{
- aux=*LC;
- while(strcmp(aux->leg,A->legajo)!=0){
- aux=aux->sig;
- }
- aux->hextr+=A->hsext;
- }
- }
- }
- void imprimerec(tcirc *LC, tcirc *aux){
- if (aux->sig==LC){
- printf("leg: %s\thsextr: %d\n",aux->leg,aux->hextr);
- }
- else{
- printf("leg: %s\thsextr: %d\n",aux->leg,aux->hextr);
- imprimerec(LC,aux->sig);
- }
- }
- void ingresadatos(tarbol **A){
- int n; char l[10];
- printf("leg: ");
- fflush(stdin);
- gets(l);
- printf("nro: ");
- scanf("%d",&n);
- cargaABB(&(*A),l,n);
- }
- //----------------------------------------------------------
- //----------------------------------------------------------
- //-------------------------------//NOSE QUE PARAMETROS LLEVAN
- int pila_vacia(){
- return (inicio==NULL);
- }
- void push(int n, char l[]){
- struct nodo *nuevo = (struct nodo *) malloc( sizeof (struct nodo) );
- strcpy(nuevo->leg,l);
- nuevo->hsext = n;
- nuevo->sig = NULL;
- if (actual==NULL){
- actual = nuevo;
- inicio = actual;
- }
- else{
- actual->sig = nuevo;
- actual = nuevo;
- }
- }
- int pop(int n,char l[]){
- struct nodo *aux = inicio;
- if (inicio==actual){
- strcpy(inicio->leg,l);
- n = inicio->hsext=n;
- free(inicio);
- inicio = NULL;
- actual = NULL;
- }
- else{
- aux = inicio;
- while (aux->sig!=actual) aux = aux->sig;
- n = actual->hsext=n;
- strcpy(inicio->leg,l);
- free(actual);
- actual = aux;
- actual->sig = NULL;
- }
- }
- void inicializar_pila(){
- inicio = NULL;
- actual = NULL;
- }
- /* ME DA ERROR
- void vaciar_pila(){
- printf("\nVaciando pila ...");
- do{
- if (inicio!=NULL){
- int n = pop();
- printf("\npila.pop() = %d", n);
- }
- }
- while(!pila_vacia());
- printf("\n");
- }*/
- void imprimir()
- {
- struct nodo *aux = inicio;
- printf("La Pila es: ");
- while(inicio!=NULL)
- {
- printf("%s %d ", inicio->leg, inicio->hsext);
- inicio = inicio->sig;
- }
- printf("\n");
- }
- //----------------------------------------------------------
- //----------------------------------------------------------
- //----------------------------------------------------------
- int menu(){
- printf("\n");
- system("pause");
- system("cls");
- printf("1- carga abb 2- imp desc 3 - genera lisc 4- Inicializar Pila 5-Mostrar Pila 6 - Vaciar pila 7- Mostrar Lista \n\n");
- int op;
- scanf("%d",&op);
- return op;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement