예제 #1
0
파일: Dlist.c 프로젝트: gandrewstone/itl
DlistHeadT* DlistCreate()
{
    DlistHeadT* ths = (DlistHeadT*) DlistHeapAllocate(NULL,sizeof(DlistHeadT));  
  DlistInit(ths);
  ths->flags |= ALLOCED;
  return ths;
}
예제 #2
0
int main(int argc, char *argv[])
{
	Dlist *dl;
	DlistNode *dn;
	int i;

	dl = DlistInit();
	if(dl == NULL)
	{
		fprintf(stderr,"DlistInit fails\n");
		exit(1);
	}

	printf("appending: ");
	for(i=0; i < 10; i++)
	{
		printf("%d ",i);
		dn = DlistAppend(dl,(Hval)i);
	}
	printf("\nReading\n");
	dn = dl->first;
	while(dn != NULL)
	{
		i = dn->value.i;
		printf("%d ",i);
		dn = dn->next;
	}
	printf("\nremoving Dlist\n");
	DlistRemove(dl);

	dl = DlistInit();
	if(dl == NULL)
	{
		fprintf(stderr,"DlistInit fails\n");
		exit(1);
	}

	printf("prepending ");
	for(i=0; i < 10; i++)
	{
		printf("%d ",i);
		dn = DlistPrepend(dl,(Hval)i);
	}
	printf("\nReading\n");
	dn = dl->first;
	while(dn != NULL)
	{
		i = dn->value.i;
		printf("%d ",i);
		dn = dn->next;
	}
	printf("\nremoving Dlist\n");
	DlistRemove(dl);

	dl = DlistInit();
	if(dl == NULL)
	{
		fprintf(stderr,"DlistInit fails\n");
		exit(1);
	}

	printf("prepending ");
	for(i=0; i < 10; i++)
	{
		printf("%d ",i);
		dn = DlistPrepend(dl,(Hval)i);
	}

	dn = dl->first;
	for(i=0; i < 5; i++)
	{
		dn = dn->next;
	}
	printf("\ndeleting %d\n",dn->value.i);
	DlistDelete(dl,dn);
	dn = dl->first;
	while(dn != NULL)
	{
		i = dn->value.i;
		printf("%d ",i);
		dn = dn->next;
	}
	printf("\nremoving Dlist\n");
	DlistRemove(dl);

	return(0);
}