int main(){ int i = 0; /*srand(time(NULL));*/ /* Initialize the skip list */ struct skipList* sl1 = (struct skipList*)malloc(sizeof(struct skipList)); initSkipList(sl1); struct skipList* sl2 = (struct skipList*)malloc(sizeof(struct skipList)); initSkipList(sl2); /* Add to the skip list M = 20 random integers in [0,100] */ for(i = 0; i < 20; i++){ addSkipList(sl1, rand() %101); addSkipList(sl2, rand() %101); } /* Print out the contents of the skip list in the breadth-first order, starting from top. While printing the elements, move to a new line every time you reach the end of one level, and move down to the lower level of the skip list. For example, the print out of a skip list with 5 elements should look like 7 7 14 29 3 7 9 14 20 */ printf("---------- skipList 1 -----"); printf("----- size %d -----\n", sizeSkipList(sl1)); printSkipList(sl1); printf("---------- skipList 2 -----"); printf("----- size %d -----\n", sizeSkipList(sl2)); printSkipList(sl2); mergeSkipList(sl1, sl2); printf("---------- mergeSkipList -----"); printf("----- size %d -----\n", sizeSkipList(sl1)); printSkipList(sl1); /* Develop test cases for evaluating the following functions: int containsSkipList(struct skipList *slst, TYPE e) int removeSkipList(struct skipList *slst, TYPE e) */ printf("---------- removed %g from skipList -----", sl1->topSentinel->next->value); removeSkipList(sl1, sl1->topSentinel->next->value); printf("----- size %d -----\n", sizeSkipList(sl1)); printSkipList(sl1); return 0; }
void test(){ /* Seed psuedo-random number generator */ srand(time(NULL)); int i; /* FIX ME */ /* Initialize the skip list */ struct skipList* list = (struct skipList*)malloc(sizeof(struct skipList)); assert(list); initSkipList(list); struct skipList* listB = (struct skipList*)malloc(sizeof(struct skipList)); assert(listB); initSkipList(listB); addSkipList(listB, 10.0); addSkipList(listB, 11.0); addSkipList(listB, 12.0); addSkipList(listB, 13.0); /* Add to the skip list M = 20 random integers in [0,100] */ i = 0; TYPE val; while(i++ < 1) { val = (double)(rand() % 101); printf("Val: %f\n", val); addSkipList(list, val); } addSkipList(list, 1.0); addSkipList(list, 3.0); addSkipList(list, 7.0); addSkipList(list, 6.0); addSkipList(list, 3.0); /* Print out the contents of the skip list in the breadth-first order, starting from top. While printing the elements, move to a new line every time you reach the end of one level, and move down to the lower level of the skip list. For example, the print out of a skip list with 5 elements should look like 7 7 14 29 3 7 9 14 20 */ printSkipList(list); printf("List size: %d\n", sizeSkipList(list)); /* Develop test cases for evaluating the following functions: int containsSkipList(struct skipList *slst, TYPE e) int removeSkipList(struct skipList *slst, TYPE e) */ /* Contains */ printf("Contains %f? %d\n", val, containsSkipList(list, val)); printf("Contains 50? %d\n", containsSkipList(list, 50.0)); /* Remove */ printf("Remove 3.0\n"); removeSkipList(list, 3.0); printSkipList(list); printf("List size: %d\n", sizeSkipList(list)); /* merge list */ printf("Merge\n"); mergeSkipList(list, listB); printSkipList(list); /* Size */ printf("Size: %d\n", sizeSkipList(list)); /* listB */ /*printf("ListB null ? %d\n", listB->topSentinel->value);*/ }