Jump to content

Lista de listas?!


tmcp

Recommended Posts

Sabes fazer uma simples lista ligada? Ou seja, tens um nodo, apontar para o próximo e assim sucessivamente até ao fim? Se sabes fazer isto, uma hipótese depois seria criar uma outra estrutura com 2 apontadores, um apontador aponta para o próximo nodo e o segundo apontador aponta para o inicio de uma determinada lista. Assim d euma forma muito básica era isto que eu faria.

Link to comment
Share on other sites

#include <stdio.h>
#include <stdlib.h>

typedef struct tipo2{
int b;
struct apt *prox;
}tipo2;

typedef struct tipo1{
int a;
tipo2 *apt;
struct tipo1 *prox;
}tipo1;




int ntipo1(tipo1 **inicio, tipo1 **fim){

int a;
tipo1 *ap;
ap=(tipo1*)malloc(sizeof(tipo1));

printf("ID:");
scanf("%d",&a);

(ap->a)=a;
(ap->apt)= ( (tipo2*) NULL);
(ap->prox)=NULL;

if(*inicio==(tipo1 *) NULL)
	*inicio=ap;
else
(*fim)->prox = ap; /* Faz a ligacao logica */

*fim = ap; /* Actualiza o ponteiro da fila */

return 1;

}

int ntipo2(tipo2 **init, tipo2 **end,tipo1 *inicio, tipo1 *ap){

int a,b;
tipo2 *apf;

printf("Qual o numero do ID?");
scanf("%d",&a);

for(ap=inicio;ap!=NULL;ap=ap->prox){
	if( (ap->a) == a)
		break;
}

printf("%d",(ap->a));

apf=(tipo2*)malloc(sizeof(tipo2));

printf("\nNum:");
scanf("%d",&b);

(apf->b)=b;

if( (ap->apt)== NULL )
	(ap->apt)=*init;

if(*init==NULL)
	*init=apf;

else
(*end)->prox = apf; /* Faz a ligacao logica */

*end = apf; /* Actualiza o ponteiro da fila */

return 0;

}

int main(void){


tipo1 *inicio;
tipo2 *init;
tipo1 *fim;
tipo2 *end;
tipo1 *ap;
tipo2 *apf;

nforn(&inicio,&fim);
nforn(&inicio,&fim);
nfact(&init,&end,inicio,ap);

for(ap=inicio;ap!=NULL;ap=ap->prox){

		for(apf=init;apf!=NULL;apf=apf->prox)
			printf("Numero do ID=%d, Numero da apt=%d",(ap->a),(apf->b));
}

return 0;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.