Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void read(int [] ,int &);
- void display(int [],int );
- void myswap(int &,int &);
- void bsort(int [],int &n);
- int main()
- {
- int n,arr[100];
- read(arr,n);
- display(arr,n);
- bsort(arr,n);
- display(arr,n);
- return 0;
- }
- //Function to read
- void read(int a[], int &n)
- {
- cout<<"Enter number of elements in array: ";
- cin>>n;
- cout<<"Enter data :"<<endl;
- for(int i=0;i<n;i++)
- cin>>a[i];
- }
- //Function to display
- void display(int a[], int n)
- {
- cout<<endl<<"Array is..."<<endl;
- for(int i=0;i<n;i++)
- cout<<a[i]<<"\t";
- cout<<endl<<"---------------";
- }
- void myswap(int &i,int &j)
- {
- int temp;
- temp=i;
- i=j;
- j=temp;
- }
- void bsort(int a[],int &n)
- {
- for(int i=0;i<n;i++)
- {
- for(int j=1;j<n;j++)
- {
- if(a[j]<a[j-1])
- myswap(a[j],a[j-1]);
- }
- }
- }
- ***OUTPUT***
- Enter number of elements in array: 4
- Enter data :
- 34
- 54
- 12
- 43
- Array is...
- 34 54 12 43
- ---------------
- Array is...
- 12 34 43 54
- ---------------
Add Comment
Please, Sign In to add comment