Exemple #1
0
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 main(){
        int i;
	int add;
	
	/*  FIX ME */
	struct skipList *list;
		
	/*  Initialize the skip list */
	initSkipList(list);
	
	/*  Add to the skip list  M = 20 random integers in [0,100] */
	
        
	for(i = 0; i < 20; i++){
		add = rand()%101;
		addSkipList(list, add);
		  
	}

	/*  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);  
        removeSkipList(list,94);
	
	/* Develop test cases for evaluating the following functions:  
	 int containsSkipList(struct skipList *slst, TYPE e) 
	 int removeSkipList(struct skipList *slst, TYPE e)
	 */
     	 	  
}
Exemple #3
0
int main (int argc, const char * argv[])
{
	const long size = atoi(argv[1]);
  	TYPE *task = (TYPE*)malloc(sizeof(TYPE)*size*2);
	int *flip = (int*)malloc(sizeof(int)*size*2);
	DynArr mainList;
	long i;
	struct skipList skippy;
	printf("Enter\n");
	initDynArr(&mainList, 10000000);	/*Avoid effects of resizing*/
	initSkipList(&skippy);
	/* create tasks */
	for(i=0;i<size*2; i++)
	{
		task[i] = createTask(rand(), "r");
		flip[i] = rand()%2;
	}
	
		
	/* add tasks to the dynamic array */
	
	for(i=0;i<size; i++)
	{
		addHeap(&mainList, task[i]);
		addSkipList(&skippy, task[i]);
	}
	
	
	
	long start = clock();
	long finish = clock();
	
	long add = 0;
	long remove = 0;
	long cnt_add = 0;
	long cnt_remove = 0;
	long sadd = 0;
	long sremove = 0;
	long scnt_add = 0;
	long scnt_remove = 0;
	for(i=0;i<size*2; i++)
	{
		if(flip[i])
		{
			start = clock();
			addHeap(&mainList, task[i]);
			finish = clock();
			add += (finish-start);
			cnt_add++;
			start = clock();
			addSkipList(&skippy, task[i]);
			finish = clock();
			sadd += (finish-start);
			scnt_add++;
		}
		else
		{
			start = clock();
			removeMinHeap(&mainList);
			finish = clock();
			remove += (finish-start);
			cnt_remove++;
			start = clock();
			removeMinSkipList(&skippy);
			finish = clock();
			sremove += (finish-start);
			scnt_remove++;
		}
	}
	
	printf("Below are the average runtimes for a given number of operations.\n");
	printf("----HEAP----\n");
	printf("Adding %ld tasks took %lf clocks.\n", cnt_add, (double)(add) / (double)(cnt_add));
	printf("Removing %ld minimums took %lf clocks.\n", cnt_remove, (double)(remove) / (double)cnt_remove);
	printf("----SKIP LIST----\n");
	printf("Adding %ld tasks took %lf clocks.\n", scnt_add, (double)(sadd) / (double)(scnt_add));
	printf("Removing %ld minimums took %lf clocks.\n", scnt_remove, (double)(sremove) / (double)scnt_remove);

	

	return 0;
}
Exemple #4
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);*/
}