[C++ ] Sortarea prin interschimbare - Tutoriale si exercitii - GAMELIFE România Jump to content

Recommended Posts

Posted

/Sortarea prin interschimbare
// se parcurge  vectorul   inversand continuturile   elementelor   alaturate   care nu  sunt  crescatoare
 

#include <iostream>

using namespace std;

int a[100], n, i,j ,k ,man, gasit ;


int main()
{
cout<<"Dati dimensiunea tabloului n = ";
cin>>n;
for(i=0; i<n; i++)
{
cout<<"a["<<i<<"] = ";
cin>>a[i];
}
do
{
    gasit=0;
    for(i=0; i<n-1; i++)
         if (a[i]>a[i+1])
    {
        man=a[i];
        a[i]=a[i+1];
        a[i+1]=man;
        gasit=1;
    }
}
while (gasit);
{
     cout<<"Tabloul ordonat crescator \n";
   for(i=0; i<n; i++) cout<<a[i]<<" ";
}
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...

Important Information