int main(int argc, char *argv[])
{
    int N = 0;
    ElementType *A;

    if (argc != 2) return -1;
    N = atoi(argv[1]);
    assert(N != 0);

    A = malloc(sizeof(ElementType)*N);
    assert(A != NULL);
    memset(A,0,N*sizeof(ElementType));


    RandomFillArray(A,N);
    printf("original array:\n");
    PrintArray(A,N);

    printf("sort start:\n");
//	InsertSort(A,N);
//	BubbleSort(A,N);
//	ShellSort_V2(A,N);
//	QuickSort(A,N);
    MergeSort(A,N);
    printf("sort end.\n");

    printf("After sort array is:\n");
    PrintArray(A,N);

    free(A);
    return 0;
}
Example #2
0
void RunQuickSort(void)
{
  int to_partition[] = {2, 1, 3, 7, 1, 3, 6, 4, 8, 3, 4, 1};
  int size = sizeof(to_partition) / sizeof(int);
  PrintArray(to_partition, size);
  Quicksort(to_partition, 0, size);
  PrintArray(to_partition, size);
}
Example #3
0
int main()
{
   int array[] = {10,9,8,7,6,5,4,3,2,1};
   int len = sizeof(array) / sizeof(int);
   PrintArray(array,len,"直接插入排序前:");
   InsertSort(array,len);
   PrintArray(array,len,"直接插入排序后:");
   return 0;
}
Example #4
0
// main - entry point
int main(int argc, const char * argv[]) {
    int numbers[10] = { 12, 445, 55, 67, 2, 7, 909, 45, 4454, 1 };
    printf("Before Insertion Sort: ");
    PrintArray(numbers, 10);
    InsertionSort(numbers, 10);
    printf("After Insertion Sort: ");
    PrintArray(numbers, 10);
    return 0;
}
Example #5
0
int main()
{
    int array[] = {7,6,5,3,4,2,1,10,9,8};
    int len = sizeof(array) / sizeof(int);
    PrintArray(array,len,"快速排序前:");
    QuickSort(array,0,len - 1);
    PrintArray(array,len,"快速排序后:");
    return 0;
}
int main(void)
{
    ElemType* const array = (ElemType*)malloc(sizeof(ElemType)*ARRAY_NUMBER );
    InitalArray(array);
    PrintArray(array);
    BinaryInsertionSort(array,ARRAY_NUMBER );
    printf("排序结果为:");
    PrintArray(array);
    return 0;
}
Example #7
0
int main()
{
  int array[] = {10,9,8,7,6,5,4,3,2,1};
  int len = sizeof(array) / sizeof(int);
  PrintArray(array,len,"冒泡排序前:");
  //BubbleSort(array,len);
  BubbleSort2(array,len);
  PrintArray(array,len,"冒泡排序后:");
  return 0;
}
Example #8
0
int main()
{
	#if 0
	int i;
	int iPos = 0 ;
	int iArr1[]={1,7 , 12 ,15,16,17,19,22,23 , 26};
	int iSize =  sizeof(iArr1)/sizeof(iArr1[0]) ;
	void **pAddr = malloc( iSize * sizeof(void *));
	for(i = 0 ; i < iSize ; ++i)
	{
		pAddr[i] = iArr1 + i ;
	}	
	PrintArray(iArr1 , iSize , &i);
	while(i != -1)
	{
		int iRet = BSearch( pAddr  , sizeof(iArr1)/sizeof(iArr1[0]) , (void *)&i , CompareFunc  ,&iPos);
		if(iRet == 0)
		{
			printf("bingo ! pos:%d\n" , iPos);
		}
		else
		{
			printf("bad luck ! pos:%d\n" , iPos);
		}
		PrintArray(iArr1 , iSize , &i);
	}
	#endif
	int i ;
	int iArr1[] = { 24 , 25};	
	int iArr2[]={1,2,3,4,5 , 8 , 9 , 23 };
	unsigned int iSize1 = sizeof(iArr1)/sizeof(iArr1[0]) ;
	unsigned int iSize2 = sizeof(iArr2)/sizeof(iArr2[0]) ;
	void **p1 = malloc(iSize1 * sizeof(void *));
	void **p2 = malloc(iSize2 * sizeof(void *));
	void **pMerge = (void **)malloc( sizeof(void *)* (iSize1 + iSize2));
	for(i = 0 ; i < iSize1 ; ++i)
        {
                p1[i] = iArr1 + i ;
        }
	for(i = 0 ; i < iSize2 ; ++i)
        {
                p2[i] = iArr2 + i ;
        }
	for(i = 0 ; i < (iSize1 + iSize2) ; ++i)
	{
			pMerge[i] = NULL ;
	}
	Merge(p1 , iSize1 , p2 , iSize2 ,CompareFunc ,  pMerge);
	for(i = 0 ; i < (iSize1 + iSize2) ; ++i)
	{
			printf("%d " , *((int *)pMerge[i]));
	}
	printf("\n");		
	return 0 ;
}
void main()
{
	int a[100];
	int n;
	RandomArray(a,n);
	PrintArray(a,n);
	//SimpleSort(a,n);
	BinaryInsertionSort(a,n);
	PrintArray(a,n);
	getch();
}
Example #10
0
int main()
{
    // data
    int values[] = {32,71,12,45,26,80,53,33}; 
    const unsigned int n = sizeof(values)/sizeof(values[0]);
    std::cout << "value before ="; PrintArray(values, n);

    BubbleSort(values, n);
    std::cout << "value after  ="; PrintArray(values, n);
    return 0;
}
Example #11
0
void main()
{
	int a[100];
	int b[100];
	int n;
	int m = 0;
	RandomArray(a,n);
	CreateNewArray(a,b,n,m);
	PrintArray(a,n);
	PrintArray(b,m);
	getch();
}
Example #12
0
int main2(void){
	int aScores[20]={0};
	int els = numsof(aScores);
	int i;
	srand((unsigned int)time(NULL));

	RandomArray(aScores);
	PrintArray(aScores);
	BubbleSort(aScores, els);
	PrintArray(aScores);

	return 0;
}
Example #13
0
void main()
{
	int a[100];
	int h[100];
	int n,k;
	RandomArray(a,n);
	PrintArray(a,n);

	GetSteps(h,k,n);
	ShellSort(a,n,h,k);
	PrintArray(a,n);
	getch();
}
Example #14
0
int main(void)
{
    int i;
    u64 begin,end;
    ElemType* const array = (int*)malloc(sizeof(int)*ARRAY_NUMBER );
    InitalArray(array);
    PrintArray(array);

    ElemType* tempArray1 =  (int*)malloc(sizeof(int)*ARRAY_NUMBER );
    ElemType* tempArray2 =  (int*)malloc(sizeof(int)*ARRAY_NUMBER );
    ElemType* tempArray3 =  (int*)malloc(sizeof(int)*ARRAY_NUMBER );
    for(i = 0; i < ARRAY_NUMBER ; i++)
    {
        tempArray1[i] = array[i];
        tempArray2[i] = array[i];
        tempArray3[i] = array[i];
    }

    //冒泡排序
    Rdtsc(&begin);
    BubbleSort(array);
    Rdtsc(&end);
    printf("冒泡排序后的数组是:");
    PrintArray(array);
    printf("花费时间为:%llu \n",end - begin);

    Rdtsc(&begin);
    BubbleSort2(tempArray1);
    Rdtsc(&end);
    printf("冒泡排序2后的数组是:");
    PrintArray(tempArray1);
    printf("花费时间为:%llu \n",end - begin);

    Rdtsc(&begin);
    BubbleSort3(tempArray2);
    Rdtsc(&end);
    printf("冒泡排序3后的数组是:");
    PrintArray(tempArray2);
    printf("花费时间为:%llu \n",end - begin);
    
    Rdtsc(&begin);
    BubbleSort4(tempArray3);
    Rdtsc(&end);
    printf("冒泡排序4后的数组是:");
    PrintArray(tempArray3);
    printf("花费时间为:%llu \n",end - begin);

    return 0;
}
Example #15
0
int main()
{
    aType testArray[] = { 7, 13, 1, 3, 10, 5, 2, 4 };
    int nA = sizeof(testArray)/sizeof(aType);

    cout << "nA: "  << nA << endl;

    cout << "Initial array contents:" << endl;
    PrintArray( testArray, nA );

    SelectionSort( testArray, nA );

    cout << "Final array contents:" << endl;
    PrintArray( testArray, nA );
}
Example #16
0
void  SelectionSort( aType A[], int nElements )
{
    int iSmallest;
    aType  tmp;
   
    cout << "------------------------" << endl;
    cout << "In SelectionSort():" << endl;

    for( int i = 0 ; i < nElements ; i++ )
    {
        cout << " Pass: "******"SelectionSort() finished" << endl;
    cout << "------------------------" << endl;
}
Example #17
0
//Function sorts pointer array according to input order
//Input: pointer array, size of array, sort order
//Output: pointer array sorted by sort order
void BubbleSort(int *array, int size, int order)
{
	int a;
	int loop = 1;

	while (loop)
	{
		loop = 0;

		for (a = 0; a < size-1; a++)
		{
			//Sorts array in ascending order
			if (order == 1)
				if (*array > *(array+1))
					{
						Swap(array, array+1);
						loop = 1;
					}

			//Sorts array in decending order
			if (order == -1)
				if (*array < *(array+1))
					{
						Swap(array, array+1);
						loop = 1;
					}

			array++;
		}

		array = array - (size - 1);
	}

	PrintArray(array, 20);
}
Example #18
0
int main() {
	int a[10];
	ScanArray(a, 10);
	MergeSort(a, 0, 9);
	PrintArray(a, 10);
	return 0;
}
// ------------------------------------------------------------
// Description	:图像处理C模式线程
// Parameter	:void
// Retrun Value	:void
// ------------------------------------------------------------
void * MultiDeepModeTCDImageProcessThread(void*)
{
	LOGI( "MultiDeepModeTCD mode image thread is start here");
	//printf( "MultiDeepModeTCD mode image thread is start here\n");
	int nCnt = 0;

	//Color Frame
	int *pMultiDeepModeTCDFrameDisp = NULL;


	while (1)
	{
		//suspend check
		ThreadSpace::GetMultiDeepModeTCDImageThread()->SuspendCheck();

		//wait m_Sem_MultiDeepModeTCD
		SynSem::GetIDSem()->m_Sem_MultiDeepModeTCD.ConsumerWait();
		//get the cycle buffer
		int nRet = MultiDeepModeTCDFrameBuffer.GetReadPointer(&pMultiDeepModeTCDFrameDisp);
		if (0 == nRet)
		{
			LOGE("GetReadPointer failed in the GetMultiDeepModeTCD mode image thread!");
			//printf("GetReadPointer failed in the GetMultiDeepModeTCD mode image thread!\n");
		}
		//printf("显示\n");

		PrintArray(DEEP_POINTS,pMultiDeepModeTCDFrameDisp);

		SynSem::GetIDSem()->m_Sem_MultiDeepModeTCD.ConsumerDone();
        nCnt++;
		LOGI( "MultiDeepModeTCD mode image thread is done,%d",nCnt);

	}

}
Example #20
0
/**
 * @brief Returns the Json representation of a Json Object.
 */
std::string JsonProcessor::PrintObject (const JsonValueObject* value, const int indent_level)
{
    int il = indent_level + 1;
    std::string in (il * indent, ' ');
    std::stringstream ss;
    ss << "{";

    bool first = true;
    for (JsonValueObject::const_iterator it = value->cbegin(); it != value->cend(); ++it) {
        JsonValueObject::ObjectPair v = *it;
        if (!first) {
            ss << ",";
        }
        ss << "\n" << in << "\"" << v.first << "\": ";
        if (v.second->IsArray()) {
            ss << PrintArray(JsonValueToArray(v.second), il);
        } else if (v.second->IsObject()) {
            ss << PrintObject(JsonValueToObject(v.second), il);
        } else {
            ss << PrintValue(v.second);
        }
        first = false;
    }

    ss << "\n" << std::string(indent_level * indent, ' ') << "}";
    return ss.str();
}
Example #21
0
void Printer::PrintValue(std::string *result, Sqrat::Object object) {
	if (object.IsNull()) {
		result->append("null");
	} else {
		if (object.GetType() == OT_TABLE) {
			PrintTable(result, object.Cast<Sqrat::Table>());
		} else if (object.GetType() == OT_ARRAY) {
			PrintArray(result, object.Cast<Sqrat::Array>());
		} else if (object.GetType() == OT_INTEGER) {
			Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%lu",
					object.Cast<unsigned long>());
			result->append(mPrintBuffer);
		} else if (object.GetType() == OT_STRING) {
			result->append("\"" + object.Cast<std::string>() + "\"");
		} else if (object.GetType() == OT_BOOL) {
			result->append(object.Cast<bool>() ? "true" : "false");
		} else if (object.GetType() == OT_FLOAT) {
			Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%f",
					object.Cast<double>());
			result->append(mPrintBuffer);
		} else {
			Vector3 *vec3 = object.Cast<Vector3*>();
			if (vec3 != NULL) {
				Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer),
						"Vector3(%f,%f,%f)", vec3->mX, vec3->mY, vec3->mZ);
				result->append(mPrintBuffer);
			}

		}
	}
}
Example #22
0
int main() {
 Legendre leg(-1., 1., 8);
 DArray darr;
 leg.FindPolynomial(darr);
cerr << "Polynomial:";
PrintArray(darr);
 return 0;
}
Example #23
0
void main()
{
	int a[100];
	int n;
	RandomArray(a,n);
	PrintArray(a,n);
	getch();
}
Example #24
0
void main()
{
	int a[100];
	int n;
	RandomArray(a,n);
	PrintArray(a,n);
	FindPosition(a,n);
	getch();
}
Example #25
0
int main(int argc, char** argv) {
	std::tr1::mt19937 mt19937;
	std::tr1::uniform_int<int> r(0, 999);

	const int Count = 16 * 32;
	std::vector<int> values(Count);
	for(int i(0); i < Count; ++i)
		values[i] = r(mt19937);

	// Build the histogram.
	int digits1[10] = { 0 };
	for(int i(0); i < Count; ++i)
		++digits1[values[i] / 100];

	// std::sort(values.begin(), values.end());

	int k = 2 * Count / 3;
	printf("Searching for k = %d.\n\n", k);
	printf("Full sequence (%d) values:\n", Count);
	PrintArray(&values[0], Count, 100);
	printf("\n");


	// Run the search on the 100's digit.
	std::vector<int> hundreds;
	IntPair result100 = ProcessDigit(&values[0], Count, 100, k, hundreds);
	printf("k is in %d for 100s digit. Scan offset for this digit is %d.\n",
		result100.first, result100.second);
	printf("Adjusted k is %d - %d = %d.\n\n\n", k, result100.second,
		k - result100.second);
	k -= result100.second;

	// Run the search on the 10's digit.
	std::vector<int> tens;
	IntPair result10 = ProcessDigit(&hundreds[0], (int)hundreds.size(), 10,
		k, tens);
	printf("k is in %d for 10s digit. Scan offset for this digit is %d.\n",
		result10.first, result10.second);
	printf("Adjusted k is %d - %d = %d.\n\n\n", k, result10.second,
		k - result10.second);
	k -= result10.second;

	// Run the search on the 1's digit.
	std::vector<int> ones;
	IntPair result1 = ProcessDigit(&tens[0], (int)tens.size(), 1, k, ones);
	printf("k is in %d for 1s digit. Scan offset for this digit is %d.\n",
		result1.first, result1.second);
	printf("Adjusted k is %d - %d = %d.\n\n\n", k, result1.second, 
		k - result1.second);
	k -= result1.second;

	for(int i(0); i < 80; ++i)
		printf("-");
	printf("\nk'th smallest element is %d!\n", ones[k]);


}
void main()
{
	int i, a[N];

	srand(21845U);
	for(i=0; i<N; ++i)
		a[i] = rand() % 1000;

	printf("排序前的序列为:\n");
	PrintArray(a, N);
	printf("\n");

	QuickSort(a, N);

	printf("排序后的序列为:\n");
	PrintArray(a, N);
	printf("\n");
}
Example #27
0
void main()
{
	int a[100];
	int n;
	RandomArray(a,n);
	PrintArray(a,n);
	DisplayResult(a,n);
	getch();
}
Example #28
0
int main(void)
{
    int arr[] = { 5, 4, 12, 36, 1, 9, 11, 24, 100, 50 };

    BubbleSort(arr, 10);
    PrintArray(arr, 10);

    return 0;
}
Example #29
0
void PrintLDAModel(LDAMODEL* m)
{
  puts("Eigenvalues"); PrintDVector(m->eval);
  puts("Eigenvectors"); PrintMatrix(m->evect);
  puts("Features");
  PrintArray(m->features);
  puts("Multivariate Normal Distribution");
  PrintArray(m->mnpdf);
  
  puts("Class Average. Each row represent a class");
  PrintMatrix(m->mu);
  
  puts("Validation...");
  puts("Senstivity"); PrintDVector(m->sens);
  puts("Specificity"); PrintDVector(m->spec);
  puts("Positive Predicted Value"); PrintDVector(m->ppv);
  puts("Negative Predicted Value"); PrintDVector(m->npv);
  puts("Accuracy"); PrintDVector(m->acc);
}
Example #30
0
int main()
{
	auto myClosure = [](MyArray::value_type number) {
		std::cout << number << std::endl;
	};
	std::cout << typeid(myClosure).name() << std::endl;
	//lambda表达式传递给function
	PrintArray(myClosure);
	return 0;
}