Search
 
SCRIPT & CODE EXAMPLE
 

CPP

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

reverse an array in c++ stl

//Reverse an array using C++ STL
#include <algorithm>  //Header file for reverse method

 int arr[] = { 1, 2, 3, 4, 5 };
 int n = sizeof(arr) / sizeof(arr[0]);  //Size of array
 reverse(arr, arr + n);
 //Now array looks like = { 5, 4, 3, 2, 1 }
 //The time complexity is O(n)

//https://www.linkedin.com/in/kalyan-santra-44589a126/
Comment

stl function to reverse an array

reverse(ar , ar + n) ; //ar is the array , n is the size
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

function for reversing an array c++ stl

// C++ program to reverse Array
// using reverse() in STL
  
#include <algorithm>
#include <iostream>
using namespace std;
  
int main()
{
    // Get the array
    int arr[] = { 1, 45, 54, 71, 76, 12 };
  
    // Compute the sizes
    int n = sizeof(arr) / sizeof(arr[0]);
  
    // Print the array
    cout << "Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
  
    // Reverse the array
    reverse(arr, arr + n);
  
    // Print the reversed array
    cout << "
Reversed Array: ";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ string replace 
Cpp :: heapsort 
Cpp :: crud with template c++ 
Cpp :: in built function to find MSB in cpp 
Cpp :: end vs cend in cpp 
Cpp :: creating large maps cpp 
Cpp :: 1822. Sign of the Product of an Array leetcode in c++ 
Cpp :: print all variables separated by comma c++ 
Cpp :: time_t c++ stack overflow 
Cpp :: c++ anti debugging 
Cpp :: strcmp in c++ header file 
Cpp :: adding two dates using necessary member function in c++ 
Cpp :: ++m in c 
Cpp :: C++ for vs while loops 
Cpp :: progress bar custom color c++ buider 
Cpp :: argument to number C++ 
Cpp :: c++ over load oprator to print variable of clas 
Cpp :: Password codechef solution in c++ 
Cpp :: c++ put a function in a other thread 
Cpp :: c++ int max value 
Cpp :: comment installer boost c++ sur windows 
Cpp :: Buy 2 Get 1 Free codechef solution in c++ 
Cpp :: c++ poitner 
Cpp :: c++ Detect Cycle in a Directed Graph 
Cpp :: txt auslesen c++ 
Cpp :: 136. Single Number leetcode solution in c++ 
Cpp :: c++ caps lock key 
Cpp :: C++ Display Numbers from 1 to 5 
Cpp :: how to delete repeated element in stack c++ 
Cpp :: initialize multiple variables to 0 c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =