SORT3


TEST CASE 1 

INPUT
7
64 34 25 12 22 11 90
OUTPUT
12 22 11 25 34 64 90 
Sorted array:11 12 22 25 34 64 90 

TEST CASE 2 

INPUT
9
64 34 25 12 22 11 90 35 26
OUTPUT
12 22 11 25 34 26 35 64 90 
Sorted array:11 12 22 25 26 34 35 64 90

#include <iostream>
using namespace std;
void printArr(int arr[], int size)
{
  cout<<"Sorted array:";
  for(int k=0;k<size;k++)
    cout<<arr[k]<<" ";
}
int main()
{
   int i,j,size,arr[100];
  cin>>size;
  for(i=0;i<size;i++)
    cin>>arr[i];
  for(i=0;i<size-1;i++)
  {
   
    for(j=0;j<size-i-1;j++)
     {
       
        if(arr[j] > arr[j+1])
        {
           int temp = arr[j+1];
          arr[j+1] = arr[j];
          arr[j] = temp;
        }
      }
     if(i == 2)
       {
         for(int a=0;a<size;a++)
           cout<<arr[a]<< " ";
         cout<<endl;
       }
  }
  printArr( arr,  size);
  return 0;
}

Comments

Popular posts from this blog

AR1

SER12

AR15