Exemple #1
0
void crt_lliststress_test()
{
	int flag = -1;
	char *errTxt = NULL;
	LinkedList *ll = initLList(errTxt);
	LLItem *llitem = NULL;
	if(ll == NULL) {
		flag = -1;
	} else {
		int i = 0;
		int *ptr_i;
		for(; i < 10; i++) {
			ptr_i  = malloc(sizeof(int));
			*ptr_i = i;
			addLLItem(ll, (void*)ptr_i, sizeof(i), errTxt);
		}
		if(ll->length != 10) flag = -1;
		// сравнение списка
		llitem = ll->Head;
		int val = 0;
		int *ptr = 0;
		for(i = 0; i < 10; i++) {
			ptr = (int *)llitem->Object;
			val = *ptr;
			printf("%d = %d \n", i, val);
			llitem = llitem->Next;
		}
		delLList(ll);
	}
	if(ll != NULL) flag = -1;
	TEST_ASSERT_TRUE(flag);
}
Exemple #2
0
int main(int argc, char **argv) {
    char *s;
    char word[80];
    int i;
    char *errorCheck;
    char *tempword;
    LinkedList *head = 0, *curr = 0;

    FILE * dictionary = fopen("/usr/share/dict/words", "r");
    if(!dictionary) {
        printf("null dictionary\n");
        return 1;
    }

    do {
        errorCheck = fgets(word, sizeof(word), dictionary);
        tempword = malloc(strlen(word) * sizeof(char));
        word[strlen(word) - 1] = '\0';
        strcpy(tempword, word);
        head = addLLItem(head, tempword);
    } while(errorCheck);

    curr = head;


    while(curr && curr->next) {
        s = curr->data;
        printf("%s\n", s);
        curr = curr->next;
    }

    while(curr && curr->prev) {
        s = curr->data;
        printf("%s\n", s);
        curr = curr ->prev;
    }

    printf("%s\n", curr->data);
}