0% found this document useful (0 votes)
3 views1 page

Binary Sort in Simple Way Using CPP

The document contains a C++ program that implements a bubble sort algorithm to sort an array of integers in ascending order. It prompts the user to enter the size of the array and its elements, displays the array before and after sorting. The sorted elements are printed to the console.

Uploaded by

mccntnd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Binary Sort in Simple Way Using CPP

The document contains a C++ program that implements a bubble sort algorithm to sort an array of integers in ascending order. It prompts the user to enter the size of the array and its elements, displays the array before and after sorting. The sorted elements are printed to the console.

Uploaded by

mccntnd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

void binarySort(int arr[], int size){


for(int i=0; i<size ; i++){
for(int j=0; j<size-1; j++){
if(arr[j]>arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nElements After Sorting:


(Ascending Order)\n";
for(int i=0; i<size; i++){
cout<<"\n\tElement # "<<i+1<<" : " << arr[i];
}
cout<<endl<<endl;
}
int main()
{
int size;

cout << "Enter the size of the array: ";


cin>>size;
//size = 3;
int arr[size];

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


cout << "Enter the Element of the array # " << i+1 <<" : ";
cin>>arr[i];
}

cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nElements Before Sorting:\n";


for(int i=0; i<size; i++){
cout<<"\n\tElement # "<<i+1<<" : " << arr[i];
}
binarySort(arr,size);

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy