Answers for "sort a stack in cpp"

C++
0

how to sort array in c++

#include <iostream>
using namespace std;
int main () {

  int n,i,j,temp;
  cout << "how many Arrays you wanna sort? ";
  cin >> n;
  cout << endl << endl;
  int a[n];
  for(i = 0;i < n; i++){
    cout << "please enter your " << i + 1 << " array : ";
    cin >> a[i];
  }
  for(i = 0; i < n; i++){
   for(j = 0; j < n - 1; j++){
    if( a[j] > a[j+1]){
     temp = a[j];
      a[j] = a[j+1];
        a[j+1] = temp;
    }
   }
  }

  cout << "nArray after sorting using default sort is : n";
    for (i = 0; i < n; i++)
      cout << a[i] << 't';

 return 0;
}
Posted by: Guest on September-10-2021

Browse Popular Code Answers by Language