Untitled

 avatar
unknown
plain_text
5 months ago
761 B
3
Indexable
#include <iostream>
using namespace std;


void bubbleSort(int array[], int size) {

  for (int step = 0; step < size -1; ++step) {
      
    for (int i = 0; i < size - step - 1; ++i) {

      if (array[i] > array[i + 1]) {

        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
      }
    }
  }
}

void printArray(int array[], int size) {
  for (int i = 0; i < size; ++i) {
    cout << "  " << array[i];
  }
  cout << "\n";
}

int main() {
 int arr[10];
	int n;
	cout<<"enter the number of elements";
	cin>>n;
	cout<<"enter the elements";
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
  bubbleSort(arr, n);
  
  cout << "Sorted Array in Ascending Order:\n";  
  printArray(arr, n);
}
Editor is loading...
Leave a Comment