Exemplo n.º 1
0
int main(int argc, char *argv[]){

////////Lista
	struct List *list;
	int i;
	
	list = init_list();

	for(i=1; i<=10; i++){
		add(list,i);
	}

	print_list(list);

	destroy_list(list);

////////Cola
	struct COLA *Cola;
	int j;
	
	Cola = init_cola();

	for(j=1; j<=10; j++){
		add(Cola,j);
	}

	print_cola(Cola);

	destroy_cola(Cola);
	
	

////////Pila

	struct Stack *stack;
	int k;
	
	stack = init_stack();

	for(k=1; k<=10; k++){
		add(stack,k);
	}

	print_stack(stack);

	destroy_stack(stack);

	return 1;
}
Exemplo n.º 2
0
void main()
{
   void init_cola (cola **p);
	void ins_cola (cola **p,int objeto);
	void retira_cola (cola **p,int *s);
	int cola_vacia (cola **p);
	int temp [MAXIMOV],tarde [MAXIMOV], acttemp [MAXIMOA];
	int acttarde [MAXIMOA],nv,nact,v,valor, actividad,aux;
	struct V grafo[MAXIMOV], g_invertido[MAXIMOV];
	cola *cola;
	struct nodo *p;
	int topo [MAXIMOV],i,suma,mayor;
	int lea_grafo (V grafo[],V g_invertido[],
			int *nv, int *nact );
	void ins_lista (V g[],int v,
			int ad, int act, int tiempo);
	void escriba_g (V g[],int nv);
	lea_grafo (grafo,g_invertido,&nv,&nact);
	escriba_g (grafo,nv);
	SALTO;
	getch();
	escriba_g (g_invertido,nv);
	SALTO;
	getch();
	for (i=1; i<=nv; i++) {
		topo [i] = 0;
		temp[i] = 0;
	}
	for (i=1; i <= nact; i++) {
		acttemp [i] = acttarde [i] = 0;
	}
	for (i=1; i <= nv; i++ ) {
		p = g_invertido [i].cab;
		while (p != NULL) {
			topo [i]++;
			p = p->sig;
		}
	}
	init_cola (&cola);
	for (i=1;i<=nv;i++)
		if (topo [i] == 0 )
			ins_cola (&cola,i);
	while (!cola_vacia(&cola)) {
		retira_cola (&cola ,&v);
		p = grafo[v].cab;
		while (p != NULL) {
			aux = p->ad;
			valor = p->tiempo;
			actividad = p->act;
			topo [aux]--;
			if (topo[aux] == 0)
				ins_cola (&cola,aux);
			suma = temp[v] + valor;
			if (suma > temp [aux] )
				temp [aux] = suma;
			acttemp [actividad] = temp [v];
			p = p->sig;
		}
	}
	mayor = temp [1];
	for (i=2; i <=nv; i++ )
		if (mayor < temp [i])
			mayor = temp[i];
	for (i=1; i<=nv; i++) {
		topo [i] = 0;
		tarde [i] = mayor;
	}
	for (i=1; i <= nv; i++ ) {
		p = grafo [i].cab;
		while (p != NULL) {
			topo [i]++;
			p = p->sig;
		}
	}
	init_cola (&cola);
	for (i=1;i<=nv;i++)
		if (topo [i] == 0 )
			ins_cola (&cola,i);
	while (!cola_vacia(&cola)) {
		retira_cola (&cola ,&v);
		p = g_invertido [v].cab;
		while (p != NULL) {
			aux = p->ad;
			valor = p->tiempo;
			actividad = p->act;
			topo [aux]--;
			if (topo[aux] == 0)
				ins_cola (&cola,aux);
			suma = tarde [v] - valor;
			if (suma < tarde [aux] )
				tarde [aux] = suma;
			acttarde [actividad] = suma;
			p = p->sig;
		}
	}


	PR("Lo mas temprano de los eventos..");
	for (i=1; i<=nv; i++) {
		printf ("%2d ",temp [i]);
	}
	SALTO;
	PR("Lo mas tarde de los eventos.....");
	for (i=1; i<=nv; i++) {
		printf ("%2d ",tarde [i]);
	}
	SALTO;
	PR("Lo mas temprano las actividades..");
	for (i=1; i<=nact; i++) {
		printf ("%2d ",acttemp [i]);
	}
	SALTO;
	PR("Lo mas tarde de las actividades..");
	for (i=1; i<=nact ; i++) {
		printf ("%2d ",acttarde [i]);
	}
	PR("\nRUTA CRITICA.....\n");
	PR("EVENTOS..");
	SALTO;
	for (i=1; i <= nv; i++)
		if (temp [i] == tarde [i])
			printf ("%2d ",i);
	PR("\nACTIVIDADES ");
	SALTO;
	for (i=1; i <= nact; i++)
		if (acttemp[i] == acttarde [i])
			printf ("%2d ",i);
	getch();
}