Quick actions

cmd+k|ctrl+k

Navigation

Languages

BubbleSorting

Snippet info

Language

Cpp

Visibility

public

Author

buteskul5.6

Created

2018-12-21T19:28:12Z

Updated

2018-12-21T19:31:34Z

#include<iostream>
#include<ctime>

using namespace std;

int main()
{
	srand(time(NULL));
	int n;
	int temp=0;

	cout << "Enter size array" << endl;
	cin >> n;

	int *array = new int[n];
	for (int i = 0; i < n; i++)
	{
		array[i] = rand() % 20;
		cout << array[i] << "\t";
	}
	cout << endl;
	//-----------------------------
	for (int i = 0; i < n-1; ++i)
	{
		for (int j = 0; j < n-1; ++j)
		{
			if (array[j+1] < array[j])
			{
				temp = array[j + 1];
				array[j + 1] = array[j];
				array[j] = temp;
			}
		}
	}
	cout << "------------------------------------------------------------" << endl;
	for (int i = 0; i < n; i++)
	{
		cout << array[i] << "\t";
	}

	cout << endl;
	   
	delete[] array;
	system("Pause");
	return 0;
}
INFO