Friday, 7 July 2017

Bubble Sorting

#include <iostream>

using namespace std;

void swap(int &a,int &b){

    int r;

    r=a;

    a=b;

    b=r;}

int main()

{

  int n;

  cin>>n;

  int a[n];

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

      cin>>a[i];

  }

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

      for(int j=0;j<n;j++){

          if(a[j]>a[j+1])

          swap(a[j],a[j+1]); }

  }

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

      cout<<a[i]<<endl;}

}

No comments:

Post a Comment

Dynamic programming problem

Given a binary matrix, find out the maximum size square sub-matrix with all 1s. For example, consider the below binary matrix. Please...