Exemple #1
0
int dl_get_wordcount(list_t *list, char *word){
	check_debug(list != NULL,
		"list is NULL.");
	check_debug(word != NULL,
		"word is NULL");
	list_t *node = NULL;
	node = dl_check(list, word);
	check_debug(node != NULL,
		"word '%s' not in list.", word);
	return node->word_count;
error:
	return 0;
}
Exemple #2
0
int main(int args, char *argv[])
{
    
    FILE *input = fopen(argv[1],"r");
    int num;
    char command;

    

     while(fscanf(input,"%c %d\n",&command,&num) != EOF)
    {
        
        
        if(command == 'a')
        dl_insert(front,num);
        else if(command == 'b')
        dl_del(front,num);
        else if(command == 'f')
        { 
        valueT val = dl_get_front(front);
        printf("front value:%d\n",val);
        }
        else if(command == 'g')
        {
        valueT val = dl_get_back(front);
        printf("Back value:%d\n",val);
        }
        else if(command == 'd')
        dl_pop_front(front);
        else if(command == 'e')
        dl_pop_back(front);
        else if(command == 'h')
        {
        valueT val = dl_check(front, num);
        printf("val exists:%d\n",val);
        }
        else if(command == 'j')
        {
            dl_insert_front(front,num);
        }
        else if(command == 'p')
        {
            printList();
        }
        
    }
    fclose(input);
    return 0;
}
Exemple #3
0
bool dl_insert_front(list_t *list, char *new_word){
	list_t *node = NULL;
	bool check_test = 0;
	check_debug(list != NULL, "List is NULL.");
	node = dl_check(list, new_word);
	if(node == NULL){
		node = calloc(1, sizeof(list_t));
		check_mem(node);
		node->word = strdup(new_word);
		node->word_count++;
		if(list->prev == NULL && list->next == NULL){
			list->prev = node;
			list->next = node;
			node->prev = list;
			node->next = list;
		} else {
			check_debug(list->prev != NULL && list->next != NULL,
				"Invalid list, list->prev: %s, list->next: %s",
				list->prev == NULL ? "NULL" : "VALID",
				list->next == NULL ? "NULL" : "VALID");
			node->next = list->next;
			node->prev = list;
			list->next->prev = node;
			list->next = node;
		}
	} else {
		check_test = 1;
		node->word_count++;
	}

	return 1;

error:
	if(check_test == 0 && node != NULL){
		if(node->word != NULL){
			free(node->word);
		}
		free(node);
	}
	return 0;	
}