[c++] Reverse Contents in Array

Procedure :

 1.Take an array.

 2.Then by default function reverse(array_name, array_name + size) .
  reverse(array_name, array_name + size) function exits in algorithm.h header file.

 3.Now print the array. 

 N.B  Here we use new and delete for dynamic memory allocation.

C++ implementation :


#include<bits/stdc++.h>
using namespace std;


int main()
{
   int n;
   cin>>n;

   int *arr = new int[n];


   for(int i=0; i<n; i++)  cin>>arr[i];

   reverse(arr, arr+n);

   for(int i=0; i<n; i++)    cout<<arr[i]<<" ";

   delete[] arr;

   return 0;
}

Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array?

Examples related to function

$http.get(...).success is not a function Function to calculate R2 (R-squared) in R How to Call a Function inside a Render in React/Jsx How does Python return multiple values from a function? Default optional parameter in Swift function How to have multiple conditions for one if statement in python Uncaught TypeError: .indexOf is not a function Proper use of const for defining functions in JavaScript Run php function on button click includes() not working in all browsers

Examples related to reverse

Right way to reverse a pandas DataFrame? Reverse Contents in Array Reverse a string without using reversed() or [::-1]? angular ng-repeat in reverse Reversing an Array in Java Reversing a String with Recursion in Java Print a list in reverse order with range()? How to reverse an std::string? Python list sort in descending order How to get a reversed list view on a list in Java?