Пример #1
0
/**
 * \ingroup ijv
 * \brief sort an ijv on the i entries ,
 *         and then on the j entries
 *
 * not yet working!!!
 */
void ijvSortij(ijvType *ijv_orig)
{

  int *perm;
  int e;

  ijvType *ijv_temp;
  
  perm = CountingSort(ijv_orig->i, ijv_orig->nnz, ijv_orig->n);
  ijv_temp = makeIJV(ijv_orig->nnz);
  ijv_temp->n = ijv_orig->n;

  for (e=0; e < ijv_orig->nnz; e++){
    ijv_temp->i[perm[e]] = ijv_orig->i[e];
    ijv_temp->j[perm[e]] = ijv_orig->j[e];
    ijv_temp->v[perm[e]] = ijv_orig->v[e];
  }
  cFree(perm);
  
  perm = CountingSort(ijv_temp->j, ijv_temp->nnz, ijv_temp->n);

  for (e=0; e < ijv_temp->nnz; e++){
    ijv_orig->i[perm[e]] = ijv_temp->i[e];
    ijv_orig->j[perm[e]] = ijv_temp->j[e];
    ijv_orig->v[perm[e]] = ijv_temp->v[e];
  }
  cFree(perm);
}
Пример #2
0
void CountingSortNULLVector()
{
	Vector* vec = NULL; 
	
	CountingSort(vec, 100);
	printf("SortNULLVector..................OK\n");
}
Пример #3
0
/**
 * \ingroup ijv
 * \brief sort an ijv on the j entries *
 *
 */
void ijvSortj(ijvType *ijv)
{

  int *perm;
  ijvType *ijv_temp;
  int e;

  ijv_temp = makeIJV(ijv->nnz);

  ijv_temp->n = ijv->n;
 

  perm = CountingSort(ijv->j, ijv->nnz, ijv->n);

  for (e=0; e < ijv->nnz; e++){
    ijv_temp->i[perm[e]] = ijv->i[e];
    ijv_temp->j[perm[e]] = ijv->j[e];
    ijv_temp->v[perm[e]] = ijv->v[e];
  }
  if (perm) cFree(perm);


  for (e=0; e < ijv->nnz; e++){
    ijv->i[e] = ijv_temp->i[e];
    ijv->j[e] = ijv_temp->j[e];
    ijv->v[e] = ijv_temp->v[e];
  }

  freeIJV(ijv_temp);

}
Пример #4
0
int main() {
	int A[] = {1,2,3,3,3};
	int* B = (int*)malloc(sizeof(int) * 5);
	int i = 0;
	CountingSort(A,B,5);
	for (i = 0; i < 5; i ++) {
		printf("\n");
		printf("%d ",B[i]);		
	}
}
Пример #5
0
void CountingSortEmptyVector()
{
	Vector* vec = NULL; 
	
	vec = VectorCreate(100, 100);
	
	CountingSort(vec, 100);
	
	printf("SortEmptyVector..................OK\n");
	
	VectorDestroy(vec);
}
Пример #6
0
int main(int argc,char* argv[])
{
	int a[]={19,9,20,36,1,8,8,51,37};
	int b[9];
	int i;
	CountingSort(a,b,9,51);
	for(i=0;i<9;i++)
	{
		printf("%d ",b[i]);
	}
	printf("\n");
	return 0;
	
}
Пример #7
0
void MassiveCountingSortTest()
{
	int vectorSize, i, j;
	int num1, num2;
	Vector* vec;
	srand(time(NULL));
	
	for(j = 0; j < RUNS; j++)
	{
		
		vectorSize = rand() % MAX_VECTOR_SIZE;

		vec = VectorCreate(vectorSize, 100);

		for(i = 0; i < vectorSize; i++)
		{
			VectorAdd(vec, rand() % MAX_NUMBER);
		}
		
		CountingSort(vec, MAX_NUMBER);
		
		VectorDelete(vec, &num1);

		for(i = 0; i < vectorSize - 1; i++)
		{
			VectorDelete(vec, &num2);
			if(num2 > num1)
			{
				printf("MassiveSortTest..................FAIL\n");
				/*VectorPrint(vec);*/
				VectorDestroy(vec);
				return;
			}
			num1 = num2;
		}

		VectorDestroy(vec);
	}

	printf("MassiveSortTest..................OK\n");
}
Пример #8
0
int testCountingSort(int* arr, int size)
{
	if(arr == NULL)
	{
		return -1;
	}
	int resultArr[MAX_ARR_NUM] = {0, };
	printf("CountingSort\nbefore:");
	for(int i = 0; i < MAX_ARR_NUM; ++i)
	{
		arr[i] = rand() % MAX_NUM;
		printf("%d ,", arr[i]);
	}
	printf("\nafter:");
	CountingSort(arr, MAX_ARR_NUM, resultArr, MAX_NUM);
	for(int i = 0; i < MAX_ARR_NUM; ++i)
	{
		printf("%d ,", resultArr[i]);
	}
	printf("\n");
	return 0;
}
Пример #9
0
void SimpleCountingSortForSingleMember()
{
	Vector* vec; 
	int a;
	
	vec = VectorCreate(100, 100);
	
	VectorAdd(vec, 5);

	CountingSort(vec, 10);
	
	VectorDelete(vec, &a);
	
	if(a == 5)
	{
		printf("SimpleSortForSingleMember..................OK\n");
	}	
	else
	{
		printf("SimpleSortForSingleMember..................FAIL\n");
	}
	
	VectorDestroy(vec);
}
Пример #10
0
void SimpleCountingSort()
{
	Vector* vec; 
	int a;
	
	vec = VectorCreate(100, 100);
	
	VectorAdd(vec, 46);
	VectorAdd(vec, 2);
	VectorAdd(vec, 83);
	VectorAdd(vec, 41);
	VectorAdd(vec, 102);
	VectorAdd(vec, 5);
	VectorAdd(vec, 17);
	VectorAdd(vec, 31);
	VectorAdd(vec, 64);
	VectorAdd(vec, 49);
	VectorAdd(vec, 18);

	CountingSort(vec, 102);
	
	VectorDelete(vec, &a);
	VectorDelete(vec, &a);
	VectorDelete(vec, &a);
	
	if(a == 64)
	{
		printf("SimpleSort..................OK\n");
	}	
	else
	{
		printf("SimpleSort..................FAIL\n");
	}
	
	VectorDestroy(vec);
}
Пример #11
0
void TimeCompare()
{
	Vector* vec;
	int i, functionsRun, sizes;
	clock_t start, end; 
	float seconds;
	ADTErr(*functions[9])(Vector* _vec) = {BubbleSort, ShakeSort, QuickSort, QuickSort_Iter, InsertionSort, ShellSort, MergeSort, MergeSort_Iter, SelectionSort};
	int vectorSizes[4] = {100, 100, 100, 100};/*TODO check for 10000*/
	
	printf("\nRunning time compare.\n");

	for(sizes = 0; sizes < 4; sizes++)
	{
		printf("\nFor vector of %d integers:\n\n", vectorSizes[sizes]);	
	
		for(functionsRun = 0; functionsRun < 11; functionsRun++)
		{
			vec = VectorCreate(100, 100);

			for(i = 0; i < vectorSizes[sizes]; i++)
			{
				VectorAdd(vec, rand() % 1000);
			}

			if(functionsRun == 9)
			{
				start = clock();
				CountingSort(vec, MAX_NUMBER);
				end = clock();
				seconds = (float)(end - start) / CLOCKS_PER_SEC;
			}
			else if(functionsRun == 10)
			{
				start = clock();
				CountingSort(vec, 3);
				end = clock();
				seconds = (float)(end - start) / CLOCKS_PER_SEC;
			}
			else 
			{
				start = clock();
				functions[functionsRun](vec);
				end = clock();
				seconds = (float)(end - start) / CLOCKS_PER_SEC;
			}

			switch(functionsRun)
			{
				case 0:
					printf("BubbleSort: %f\n", seconds);
					break;
				case 1:
					printf("ShakeSort: %f\n", seconds);
					break;
				case 2:
					printf("QuickSort: %f\n", seconds);
					break;
				case 3:
					printf("QuickSort_Iter: %f\n", seconds);
					break;
				case 4:
					printf("InsertionSort: %f\n", seconds);
					break;
				case 5:
					printf("ShellSort: %f\n", seconds);
					break;
				case 6:
					printf("MergeSort: %f\n", seconds);
					break;
				case 7:
					printf("MergeSort - Iterative: %f\n", seconds);
					break;
				case 8:
					printf("SelectionSort: %f\n", seconds);
					break;
				case 9:
					printf("Counting: %f\n", seconds);
					break;
				case 10:
					printf("Radix: %f\n", seconds);
					break;
			}

			VectorDestroy(vec);
		}
	}
}
Пример #12
0
int main(){
	int array[] = {0,4,55,2,5,4,0,55,2,55,123,123,123,4,4,2,2,2,2,2};
	CountingSort(array, sizeof(array)/sizeof(int), 123);
	PRINT_INT_ARRAY(array, sizeof(array)/sizeof(int));
	return 0;
}
Пример #13
0
void Sort::Show()
{
    CountingSort();
    ShowList(transIn);
    ShowList(outValue);
}