ESTE ES EL MAIN
Código:
ESTE ES EL TDAPILA.H Y TDAPILA.C#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "tdapila.h"
typedef struct nodito
{
char NyA[13];
float tiempo;
struct nodito *sigs;
}TNODITO;
typedef TNODITO *TSUBLISTA;
typedef struct nodo
{
char cod_dep[7];
float tiempo_prom;
int cant_dep;
TSUBLISTA sub;
struct nodo *sig;
}TNODO;
typedef TNODO *TLISTA;
void CargaListaSub(TLISTA *pl);
void CargaPila(TPILA *pila);
void MuestraLista(TLISTA pl);
void IngresoEnLista(TLISTA *pl,TELEMENTOP elem);
int main()
{
TLISTA lista;
TPILA pila;
TELEMENTOP elem;
iniciap(&pila);
CargaListaSub(&lista);
CargaPila(&pila);
while(!vaciap(pila))
{
sacap(&pila,&elem);
IngresoEnLista(&lista,elem);
}
MuestraLista(lista);
}
void CargaPila(TPILA *pila)
{
TELEMENTOP elem;
char NyA[13],cod_dep[7];
float tiempo;
printf("PILA : Ingresa Nombre de deportista\n");
fflush(stdin);
while((gets(NyA)!=NULL) && (!llenap(*pila)))
{
strcpy(elem.NyA,NyA);
printf("Ingresa el código de deporte\n");
fflush(stdin);
gets(cod_dep);
strcpy(elem.cod_dep,cod_dep);
printf("Ingrese el tiempo\n");
fflush(stdin);
scanf("%f",&tiempo);
elem.tiempo=tiempo;
ponep(pila,elem);
printf("PILA: Ingresa Nombr de deportista\n");
fflush(stdin);
gets(NyA);
}
}
void CargaListaSub(TLISTA *pl)
{
TLISTA aux; TSUBLISTA auxs;
char cod_dep[7],NyA[13];
float tiempo_prom,tiempo;
int cant_dep,cont;
*pl=NULL;
printf("Ingrese COD DEPORTE\n");
fflush(stdin);
while(gets(cod_dep)!=NULL)//Ingreso de la lista, nodo a nodo//
{
aux=(TLISTA)malloc(sizeof(TNODO));
strcpy(aux->cod_dep,cod_dep);
printf("Ingrese tiemp promedio\n");
fflush(stdin);
scanf("%f",&tiempo_prom);
aux->tiempo_prom=tiempo_prom;
printf("Ingrese cantidad de deportistas\n");
fflush(stdin);
scanf("%d",&cant_dep);
aux->cant_dep=cant_dep;
aux->sig=(*pl); (*pl)=aux;
aux->sub=NULL;
cont=0;
printf("Ingrese nombre de deportista\n");
gets(NyA);
while((gets(NyA)!=NULL) && (cont<cant_dep))//INGRESA NODOS SUBLISTA//
{
auxs=(TSUBLISTA)malloc(sizeof(TNODITO));
strcpy(auxs->NyA,NyA);
printf("Ingrese el tiempo\n");
fflush(stdin);
scanf("%f",&tiempo);
auxs->tiempo=tiempo;
auxs->sigs=aux->sub;
aux->sub=auxs;
cont++;
if(cont<cant_dep)
{
printf("Ingrese nombre de deportista\n");
gets(NyA);
}
}
printf("Ingrese COD DEPORTE\n");
fflush(stdin);
}
}
void MuestraLista(TLISTA pl)
{
TSUBLISTA auxs;
while(pl!=NULL)
{
printf("%s\t %d\t %d\t\n",pl->cod_dep,pl->tiempo_prom,pl->cant_dep);
auxs=pl->sub;
while(auxs!=NULL)
{
printf("%s\t %d\t\n ",auxs->NyA,auxs->tiempo);
auxs=auxs->sigs;
}
pl=pl->sig;
}
}
void IngresoEnLista(TLISTA *pl,TELEMENTOP elem)
{
TLISTA aux,nuevo;TSUBLISTA auxs;
aux=*pl;
while((strcmp(elem.cod_dep,aux->cod_dep)!=0) && (aux!=NULL))
aux=aux->sig;
if(aux=NULL)
{
nuevo=(TLISTA)malloc(sizeof(TNODO));
strcpy(nuevo->cod_dep,elem.cod_dep);
nuevo->tiempo_prom=elem.tiempo;
nuevo->cant_dep++;
nuevo->sig=aux; aux=nuevo;
nuevo->sub=NULL;
nuevo->sig=*pl; *pl=nuevo;
auxs=(TSUBLISTA)malloc(sizeof(TNODITO));
strcpy(auxs->NyA,elem.NyA);
auxs->tiempo=elem.tiempo;
auxs->sigs=aux->sub;
aux->sub=auxs;
}
if(((aux->sub=NULL) && (elem.tiempo<(aux->tiempo_prom))) || (elem.tiempo<aux->tiempo_prom))
{
auxs=(TSUBLISTA)malloc(sizeof(TNODITO));
strcpy(elem.NyA,auxs->NyA);
auxs->tiempo=elem.tiempo;
auxs->sigs=aux->sub;
aux->sub=auxs;
aux->cant_dep++;
aux->tiempo_prom+=auxs->tiempo;
aux->tiempo_prom=(aux->tiempo_prom)/(aux->cant_dep);
}
}
Código:
#define MAXPILA 6
typedef struct TELEMENTOP
{
char NyA[13],cod_dep[7];
float tiempo;
}TELEMENTOP;
typedef struct{
TELEMENTOP vp[MAXPILA];
int tope;}TPILA;
void iniciap(TPILA *p);
int vaciap(TPILA pila);
int llenap(TPILA pila);
void ponep(TPILA *p, TELEMENTOP elem);
void sacap(TPILA *p, TELEMENTOP *pelem);
void consultap(TPILA pila, TELEMENTOP *pelem);
#include "tdapila.h"
void iniciap(TPILA *p)
{
p->tope=0;
};
int vaciap(TPILA pila)
{
return pila.tope==0;
};
int llenap(TPILA pila)
{
return pila.tope==MAXPILA;
};
void ponep(TPILA *p, TELEMENTOP elem)
{
p->vp[(p->tope)++]=elem;
};
void sacap(TPILA *p, TELEMENTOP *pelem)
{
--(p->tope);
*pelem= p->vp[ p->tope];
};
void consultap(TPILA pila, TELEMENTOP *pelem)
{
*pelem= pila.vp[pila.tope -1];
};


