Esempio n. 1
0
void xthread::putJoineeQueue(xthread * joinee) {
  listInsertHead(&toqueue, &joinee->joinqueue);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    List list;
    Data *data[6];

    int i, errors = 0;

    for (i = 0; i < 6; i++) {
        data[i] = calloc(1, sizeof(Data));
    }

    listInitialize(&list);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[1]);
    listAppendTail(&list, data[2]);
    listAppendTail(&list, data[3]);

    TEST_INT(listLength(&list), 4);
    TEST_INT(listIsEmpty(&list),  FALSE);

    TEST_PTR(listHead(&list), data[0]);
    TEST_PTR(listTail(&list), data[3]);

    TEST_PTR(listNext(data[0]), data[1]);
    TEST_PTR(listNext(data[1]), data[2]);
    TEST_PTR(listNext(data[2]), data[3]);
    TEST_PTR(listNext(data[3]), NULL);

    TEST_PTR(listPrev(data[3]), data[2]);
    TEST_PTR(listPrev(data[2]), data[1]);
    TEST_PTR(listPrev(data[1]), data[0]);
    TEST_PTR(listPrev(data[0]), NULL);

    TEST_PTR(listContaining(data[0]), &list);
    TEST_PTR(listContaining(data[1]), &list);
    TEST_PTR(listContaining(data[2]), &list);
    TEST_PTR(listContaining(data[3]), &list);

    listRemove(&list, data[0]);
    listRemove(&list, data[1]);
    listRemove(&list, data[2]);
    listRemove(&list, data[3]);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    TEST_PTR(listContaining(data[0]), NULL);
    TEST_PTR(listContaining(data[1]), NULL);
    TEST_PTR(listContaining(data[2]), NULL);
    TEST_PTR(listContaining(data[3]), NULL);

    listInsertHead(&list, data[3]);
    listInsertHead(&list, data[2]);
    listInsertHead(&list, data[1]);
    listInsertHead(&list, data[0]);

    TEST_INT(listLength(&list), 4);
    TEST_INT(listIsEmpty(&list),  FALSE);

    TEST_PTR(listHead(&list), data[0]);
    TEST_PTR(listTail(&list), data[3]);

    TEST_PTR(listNext(data[0]), data[1]);
    TEST_PTR(listNext(data[1]), data[2]);
    TEST_PTR(listNext(data[2]), data[3]);
    TEST_PTR(listNext(data[3]), NULL);

    TEST_PTR(listPrev(data[3]), data[2]);
    TEST_PTR(listPrev(data[2]), data[1]);
    TEST_PTR(listPrev(data[1]), data[0]);
    TEST_PTR(listPrev(data[0]), NULL);

    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveTail(&list), data[3]);
    TEST_PTR(listRemoveTail(&list), data[2]);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[3]);
    listAppend(&list, data[1], data[0]);
    listInsert(&list, data[2], data[3]);

    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveTail(&list), data[3]);
    TEST_PTR(listRemoveTail(&list), data[2]);

    data[0]->i = 3;
    data[1]->i = 4;
    data[2]->i = 5;
    data[3]->i = 1;
    data[4]->i = 2;
    data[5]->i = 3;

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[1]);
    listAppendTail(&list, data[2]);
    listAppendTail(&list, data[3]);
    listAppendTail(&list, data[4]);
    listAppendTail(&list, data[5]);

    listSort(&list, cmp);

    TEST_PTR(listRemoveHead(&list), data[3]);
    TEST_PTR(listRemoveHead(&list), data[4]);
    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[5]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveHead(&list), data[2]);

    exit(errors);
}
Esempio n. 3
0
int main() {
    Node* list = NULL;
    listInsertHead(1, list);
    listInsertHead(9, list);
    listInsertHead(7, list);
    listInsertHead(5, list);
    Node* list2 = NULL;
    listInsertHead(2, list2);
    listInsertHead(3, list2);
    listInsertHead(6, list2);
    std::cout << "L1: ";
    display(list);
    std::cout << "L2: ";
    display(list2);
    Node* ptr = findNode(list, 7);
    Node* aPtr = findNode(list2, 6);
    spliceLists(ptr, aPtr);
    std::cout << "L1: ";
    display(list);
    std::cout << "L2: ";
    display(list2);
    std::cout << "============" << std::endl;
    Node* target = NULL;
    listInsertHead(6, target);
    listInsertHead(5, target);
    listInsertHead(4, target);
    listInsertHead(2, target);
    listInsertHead(3, target);
    listInsertHead(2, target);
    listInsertHead(3, target);
    listInsertHead(2, target);
    listInsertHead(1, target);
    std::cout << "Target: ";
    display(target);
    Node* match1 = NULL;
    listInsertHead(1, match1);
    Node* p = isSublist(target, match1);
    if (p) {
        display(p);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    Node* match2 = NULL;
    listInsertHead(9, match2);
    listInsertHead(3, match2);
    Node* q = isSublist(target, match2);
    if (q) {
        display(q);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    Node* match3 = NULL;
    listInsertHead(3, match3);
    listInsertHead(2, match3);
    Node* r = isSublist(target, match3);
    if (r) {
        display(r);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    Node* match4 = NULL;
    listInsertHead(6, match4);
    listInsertHead(5, match4);
    listInsertHead(4, match4);
    listInsertHead(2, match4);
    Node* s = isSublist(target, match4);
    if (s) {
        display(s);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    Node* match5 = NULL;
    listInsertHead(4, match5);
    listInsertHead(2, match5);
    listInsertHead(3, match5);
    listInsertHead(2, match5);
    Node* t = isSublist(target, match5);
    if (t) {
        display(t);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    Node* match6 = NULL;
    listInsertHead(7, match6);
    listInsertHead(6, match6);
    listInsertHead(5, match6);
    Node* u = isSublist(target, match6);
    if (u) {
        display(u);
    }
    else {
        std::cout << "Failed to match" << std::endl;
    }
    system("pause");
}