[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Dumt problem med länkad lista.



Joachim Holst <sslug@sslug> writes:

[...]

> 	while(1)
> 	{
> 		printf("Ange ett heltal > ");
> 		scanf("%d",&i);
> 		if(i==-1)
> 			break;
> 		
> 		ny=(struct Test*)malloc(sizeof(struct Test));
> 		init(ny);
> 		ny->varde=i;
> 		org=ny;
> 		ny->nasta=org;

Byt om på de to linier. Ellers er ny->nasta == ny, og sæt org=NULL før
løkken. Jeg bruger gerne et for-loop til at gennemløbe en liste

  for(ny=org; ny; ny=ny->nasta)
    printf("%d\n", ny->varde);

Indsæt et element:

  ny->varda=i;
  ny->nasta=org;
  org=ny;

Slet et element:

  ny=org;
  org=org->nasta;
  free(ny);

-- 
Jakob Stoklund Olesen, Department of Mathematics, University of Aarhus
http://www.imf.au.dk/~stoklund/          PGP public key ID: 0x4f06279d


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *