Пример #1
0
int main()
{
	const int ARRAY_SIZE = 10;
	int testArray[ARRAY_SIZE];
//	int *testArray2;

	BubbleSort<int> bsobj;

	srand((unsigned int)time(0));

	for (int i = 0; i < ARRAY_SIZE; i++)
	{
		testArray[i] = 1 + rand() % 50;
		cout << testArray[i] << endl;
	}

	vector<int> testVect(testArray, testArray + ARRAY_SIZE);
	vector<int> testVect2(testVect.size());

	cout << "-------------END OF UNSORTED ARRAY-----------------" << endl << endl;

	testVect2 = bsobj.bubbleSort(testVect);

	for (size_t i = 0; i < testVect.size(); i++)
	{
		cout << testVect2[i] << endl;
	}

	cin.get();
	return 0;
}
Пример #2
0
int main()
{
	//待排数据输入方式:
		/*int N = 0;
		cout << "排序数据个数:\n";
		cin >> N;
		int* A = new int[N];
		cout << "请输入待排序的数据:\n";
		for (int i = 0; i < N; i++)
		{
		cin >> A[i];
		}*/
	//数据直接给定	
		int B[N] = { 1, 6, 3, 5, 2, 4 };
		int C[13] = { 54, 35, 48, 36, 27, 12, 44, 44, 8, 14, 26, 17, 2 };
		int* A = C;

	//从文件中读取,大量数据,计算时间复杂度
		
	printResult("待排原始数据:", C, N);

	BubbleSort bubble;
	bubble.bubbleSort(A,N);
	printResult("bubbleSort", A, N);

	SelectionSort select;
	select.selectionSort(A, N);
	printResult("selectSort", A, N);

	InsertionSort insert;
	insert.insertionSort(A, N);
	printResult("InsetSort", A, N);

	MergeSort merge;
	merge.mergeSort(A, N);
	printResult("MergeSort", A, N);

	QuickSort qucik;
	qucik.quickSort(A, N);
	printResult("QucikSort",A,N);

	QuickSort2 qucik2;
	qucik2.quickSort(A, N);
	printResult("QucikSort2", A, N);

	HeapSort heap;
	heap.heapSort(A, N);
	printResult("heapSort", A, N);

	HeapSort2 heap2;
	heap2.heapSort(A, N);
	printResult("heapSort2", A, N);


	ShellSort shell;
	shell.shellSort(A,N);
	printResult("shellSort", A, N);

	return 0;
}
Пример #3
0
int main()
{
    int arr[]= {2,4,7,9,8,6};
    BubbleSort a;
    a.bubbleSort(arr,6);
    for(int i=0; i<6; i++)
        cout<<arr[i]<<" ";
    cout<<endl;
    return 0;
}