sortowanie babelkowe

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
710 B
2
Indexable
#include<stdio.h>
#include<iostream>


int main()
{
	int arr[] = {2, 5, 213, 1, 11, 652, 23, 213, 15, 513 ,3 ,515 ,66, 86, 15, 213, 34};
	int temp = 0;
	int done = 1;
	int cnt = 0;

	int ile_obejsc1 = 0;
	int ile_obejsc2 = 0;

	int length = sizeof(arr) / sizeof(*arr);

	while (done)
	{
		cnt = 0;
		for (int i = 1; i < length; i++)
		{
 			if (arr[i] < arr[i - 1])
			{
				temp = arr[i];
				arr[i] = arr[i - 1];
				arr[i - 1] = temp;
			}
			else
				cnt++;
		}
		if (cnt >= length - 1)
			done = 0;
		ile_obejsc1++;
	}
	for (int i = 0; i < length; i++)
		printf("arr [%i] = %d\n", i, arr[i]);
	std::cout << std::endl << ile_obejsc1 << std::endl << cnt;

	return 0;
}