예제 #1
0
int main() {
	int array[LINK_LENGTH] = { 1, 3, 4, 2, 9, 6, 7, 5, 0, 8 };
	LinkList L;
	int i = 0;
	NODE *node;

	printf("Array is: ");
	while (i < LINK_LENGTH) {
		printf("%d ", array[i]);
		i++;
	}
	printf("\n");

	//0. create
	printf("Create_List\n");
	L = Create_List(array);
	Print_List(L);

	//1. find
	printf("\n");
	printf("Find_List\n");
	Print_List(L);
	node = Find_List(L, 3);
	Print_NODE(node);

	//2. update
	printf("\n");
	Print_List(L);
	printf("Update_List\n");
	Update_List(L, 3, 23);
	Print_List(L);

	//3. insert
	printf("\n");
	Print_List(L);
	printf("Insert_List\n");
	Insert_List(L, 3, 99);
	Print_List(L);

	//4. delete
	printf("\n");
	Print_List(L);
	printf("Delete_List\n");
	Delete_List(L, 8);
	Print_List(L);

	//5. free
	printf("\n");
	Print_List(L);
	printf("Free resource!\n");
	Free_List(L);
	Print_List(L);
	return 0;
}
예제 #2
0
파일: linklist.c 프로젝트: qiyao/xcc
void
ARY_Free_List ( LNK_LST_ARY *ary )
{
  INT32 n_elems = ARY_LST_n_elems(ary);
  INT32 i;

  for (i=0; i<n_elems; ++i)
    Free_List ( ARY_LST_Elem(ary,i) );

  (void) lnk_lst_free(LST_lists(ary));     /* free the headers */
}
예제 #3
0
파일: lists_test.c 프로젝트: tcd4/clibs
void List_Test()
{
    List *list, *temp, *nomemleak;
    int *start, *prepend, *append;

    printf( "\n#### List test ####\n" );

    start = C_New( int, 1 );
    *start = 5;
    prepend = C_New( int, 1 );
    *prepend = 0;
    append = C_New( int, 1 );
    *append = 9;

    printf( "start: %i\n", *start );
    printf( "prepend: %i\n", *prepend );
    printf( "append: %i\n", *append );

    /* New_List test */
    list = New_List( start );
    if( !list )
    {
	printf( "NULL list" );
	exit( -1 );
    }
    if( list->next )
    {
	printf( "next in the list isn't NULL" );
    }
    if( list->data )
    {
	printf( "start data: %i\n", *( int* )( list->data ) );
    }

    /* Length_Of_List test */
    printf( "length: %i\n", ( int )( Length_Of_List( list ) ) );

    /* Prepend_To_List test */
    temp = Prepend_To_List( list, prepend );
    if( temp ) list = temp;
    temp = Prepend_To_List( list, prepend );
    if( temp ) list = temp;

    /* Append_To_List test */
    temp = Append_To_List( list, append );
    if( temp ) list = temp;
    temp = Append_To_List( list, append );
    if( temp ) list = temp;

    /* Length_Of_List test */
    printf( "length: %i\n", ( int )( Length_Of_List( list ) ) );


    /* Find_In_List test */
    temp = Find_In_List( list, start );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, prepend );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, append );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );
    temp = Find_In_List( list, NULL );
    if( temp ) printf( "found: %i\n", *( int* )( temp->data ) );

    /* Remove_From_List test */
    list = Remove_From_List( list, start, FALSE );
    list = Remove_From_List( list, append, TRUE );

    /* End_Of_List test */
    temp = End_Of_List( list );
    printf( "last: %i\n", *( int* )( temp->data ) );
    
    /* Duplicate_List test */
    temp = Duplicate_List( list );
    nomemleak = temp;
    while( temp )
    {
	printf( "dup: %i\n", *( int* )( temp->data ) );
	temp = temp->next;
    }

    /* print values in the List */
    printf( "data in the list\n" );
    temp = list;
    while( temp )
    {
	printf( "data: %i\n", *( int* )( temp->data ) );
	temp = temp->next;
    }

    /* Free_List test */
    temp = NULL;
    Free_List( &nomemleak );
    Free_List( &list );
}