#include<iostream>
using namespace std;
int n;
class Array
{
public:
int ar[50];
    void getval()
    {
cout<<"Enter size of the array: ";
cin>>n;
cout<<"Enter array elements: "<<endl;
        for(int i=0;i<n;i++)
cin>>ar[i];
    }
    void swap(int *p,int *q)
    {
int temp=*p;
        *p=*q;
        *q=temp;
    }
    void check(Array obj)
    {
        for(int i=0;i<n-1;i++)
        {
            for(int j=0;j<n-i-1;j++)
            {
                if(obj.ar[j]>obj.ar[j+1])
                    swap(&obj.ar[j],&obj.ar[j+1]);
            }
        }
        print(obj);
    }
    void print(Array obj)
    {
cout<<"The sorted array is: "<<endl;
        for(int i=0;i<n;i++)
cout<<obj.ar[i]<<" ";
    }
};
int main()
{
    Array obj1,obj2;
    obj1.getval();
    obj2.check(obj1);
}
Government Exams Info
Bubble.cpp
Subscribe to:
Comments (Atom)
- 
Capgemini has issued a notification for the recruitment of Architect Posts Vacancy at Various posts. Interested candidates can apply by At...
- 
#include<iostream> using namespace std; int n; class Array { public: int ar[50]; void getval() { cout<...
- 
MasterCard has issued a latest notification for the recruitment of Manager, Specialist & Engineer Post Vacancy at Various posts.Othe...
