Пример #1
0
void
listAppend(Thread* t, object list, object value)
{
  PROTECT(t, list);

  ++ listSize(t, list);
  
  object p = makePair(t, value, 0);
  if (listFront(t, list)) {
    set(t, listRear(t, list), PairSecond, p);
  } else {
    set(t, list, ListFront, p);
  }
  set(t, list, ListRear, p);
}
Пример #2
0
int main(void)
{
    ListNode* testList = NULL;
    ListNode* node = listPushBack(&testList);
    node->data = allocData(1);
    printf("test 1\nsize = %u, last id = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushBack(&testList); //->data = allocData(i);
        node->data = allocData(i);
    }
    printf("test 2\nsize = %u, last id = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushFront(&testList);
        node->data = allocData(i);
    }
    printf("test 3\nsize = %u, first id = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listInsert(listNext(&testList, 50));
        node->data = allocData(i);
    }
    printf("test 4\nsize = %u, id(100) = %i\n", listSize(&testList), getId(listNext(&testList, 100)->data));
    //--------
    listFree(&testList);
    if(listEmpty(&testList))
        printf("test4: list empty\n");
    //--------
    for(int i = 0; i < 100; ++i) {
        node = listPushFront(&testList);
        node->data = allocData(i);
    }
    listErase(&testList, listFront(&testList));
    printf("test 5\nsize = %u, id(0) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    listErase(&testList, listFront(&testList));
    //--------------
    listEraseRange(&testList, listNext(testList, 10), listNext(testList, 20));
    node = testList;
    for(int i = 0; i < 30; ++i) {
        printf("id(%d) = %d\n", i, ((ListData*)(node->data))->id);
        node = node->next;
    }
    printf("test 6\nsize = %u, id(10) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------------
    listPopBack(&testList);
    printf("test 7\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------------
    listPopFront(&testList);
    printf("test 8\nsize = %u, id(front) = %i\n", listSize(&testList), getId(listFront(&testList)->data));
    //--------------
    listResize(&testList, 10);
    printf("test 9\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    //--------------
    listResize(&testList, 20);
    node = testList;
    for(int i = 0; i < 20; ++i) {
        node->data = allocData(i);
        node = node->next;
    }
    printf("test 10\nsize = %u, id(back) = %i\n", listSize(&testList), getId(listBack(&testList)->data));
    return 0;
}