Exemplo n.º 1
0
//  		  FIXME
//  		    ||
//  		    \/
struct tree *makePathTree(struct listHeader *mlH)
{
	struct list *mlist1 = (*mlH).start, *mlist2;

	while( (*mlH).start != (*mlH).end ){

		mlist1 = (*mlH).start;
		mlist2 = (*mlist1).next;

		// cria um novo nó contendo como filhos os dois primeiros da lista ordenada
		// 		e insere ordenadamente como um novo item da lista
		(*mlist1).tree = createTree(
			(*(*mlist1).tree).freq + (*(*mlist2).tree).freq,
			'\0',
			(*mlist1).tree, (*mlist2).tree
		);

		// printf("\t %d: %d\n", (*(*mlist3).tree).c, (*(*mlist3).tree).freq ); // debug

		insertSortedList(mlH, mlist1);

		// remove
		(*mlH).start = (*mlist2).next;
		(*mlH).size--;
		// free(mlist2);

	}

	return (*mlist1).tree;
}
Exemplo n.º 2
0
void test_insert_into_sorted_list()
{
    printf("Testing insertSortedList ...\n");
    List_Pointer head = init(10);
    print(head);
    insertSortedList(head, 7);
    print(head);
    insertSortedList(head, 0);
    print(head);
    insertSortedList(head, 17);
    print(head);
    printf("\n");
    
    head = init(0);
    print(head);
    insertSortedList(head, 7);
    print(head);
}
Exemplo n.º 3
0
// cria lista de arvores de um dado vetor de pesos
struct listHeader *vectorToListOfTrees(unsigned int *v)
{
	struct listHeader *mlH = createList(NULL); //cria lista
	for(int i = 0; i < 150; i++){
		if(v[i] != 0){
			// printf(".");
			struct list *mlist = (struct list*)malloc(sizeof(struct list));
			(*mlist).tree = createTree(v[i], i, NULL, NULL);
			insertSortedList(mlH, mlist);
		}
	}

	return mlH;
}
Exemplo n.º 4
0
    ListNode *insertionSortList(ListNode *head)
    {
        ListNode* sortedHead = NULL;

        while (head)
        {
            ListNode* node = head;
            head = head->next;
            node->next = NULL;

            insertSortedList(sortedHead, node);
        }

        return sortedHead;
    }