Exemplo n.º 1
0
int main(int argc, char* argv[])
{

	int arr[15] ;
	arr_init(arr, 15);
	arr_show("before", arr, 15);
	buble_sort(arr, 15);
	arr_show("buble", arr, 15);

	arr_init(arr, 15);
	arr_show("before", arr, 15);
	select_sort(arr, 15);
	arr_show("select", arr, 15);

	arr_init(arr, 15);
	arr_show("before", arr, 15);
	insert_sort(arr, 15);
	arr_show("insert", arr, 15);

	arr_init(arr, 15);
	arr_show("before", arr, 15);
	quick_sort(arr, 15);
	arr_show("quick", arr, 15);

	arr_init(arr, 15);
	arr_show("before", arr, 15);
	heap_sort(arr, 15);
	arr_show("heap", arr, 15);
	return 0 ;
}
node* ordenar_lista(node **lista, int qtd_nos) {

	node *array = lista_to_array(*lista, qtd_nos);

	buble_sort(array, qtd_nos); // ordenando a lista

	lista = array_to_lista(&array, qtd_nos);
	return lista;
}
Exemplo n.º 3
0
void BufferTest(std::vector<T> &buf) {
    if (not buf.size()) {
        throw std::runtime_error("Передан пустой массив \"" + utils::Demangle(typeid(T).name()).string() + "\".");
    }
    std::cout << "Массив типа \"" << utils::Demangle(typeid(T).name()).string() << "\", размер=" << buf.size() << "\n";
    std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();
    sort::exchange::BubbleSort buble_sort(buf);
    std::chrono::steady_clock::time_point stop_time = std::chrono::steady_clock::now();
    std::chrono::nanoseconds nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(stop_time - start_time);
    std::chrono::seconds secs = std::chrono::duration_cast<std::chrono::seconds>(nsecs);
    std::cout << "Время сортировки: " << secs.count() << " сек. или " << nsecs.count() << " н.сек.\n";
    std::cout << "------------------------------------------------------\n";
}
Exemplo n.º 4
0
int main(int argc,char* argv[])
{
    int arr[N] = {0};
    srand(time(NULL));
    int index;
    printf("before sort:\n");
    for(index=0;index<N;index++)
    {
        arr[index] = rand()%100;
        printf("%3d",arr[index]);
    }
    printf("\n");
    buble_sort(arr,N);
    printf("after sort:\n");
    for(index=0;index<N;index++)
    {
        printf("%3d",arr[index]);
    }
    printf("\n");

}
Exemplo n.º 5
0
int main ()
{
	double *arr;
	int n;
	int i;
	FILE *fp;
	fp = fopen("data.txt", "r");
	if (fp == NULL)
	{
		printf("Can't open file \n");
		return -1;
	}
	if (fscanf(fp, "%d", &n) != 1)
	{
		printf("Wrong content \n");
		fclose(fp);
		return -2;
	}
	arr = (double *) malloc(n * sizeof(double));
	for (i = 0; i < n; i++)
	{
		if (fscanf(fp, "%lf", &arr[i]) != 1)
		{
			printf("Wrong content \n");
			fclose(fp);
			return -2;
		}
	}
	fclose(fp);
	buble_sort(arr, n);
	for (i = 0; i < n; i++)
	{
		printf("%lf \n", arr[i]);
	}
	free (arr);
	return 0;
}