Answers for "sort c++ built in function for array"

C++
1

C++ array sort method

#include <algorithm>
#include <iostream>
#include <array>
using namespace std;

int main() {
    array<int, 5> arraysort{ 4,2,3,5,1 };
    sort(arraysort.begin(), arraysort.end());
    for (int i = 0; i < arraysort.size(); i++) {
        cout << arraysort[i] << " ";
    }
	return 0; 
}
Posted by: Guest on August-09-2021
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

Code answers related to "sort c++ built in function for array"

Browse Popular Code Answers by Language