reverse an array in cpp

Solutions on MaxInterview for reverse an array in cpp by the best coders in the world

showing results for - "reverse an array in cpp"
Guadalupe
09 Jul 2016
1
2int main(){    
3  	int arr[5] = {1,3,2,4,5};
4	sort(arr, arr+5, greater<int>()); 
5  	// arr == {5,4,3,2,1}
6  	return 0;
7}
8
Cyrus
10 Mar 2016
1#include <iostream>
2using namespace std;
3int main()
4{		// While loop
5	const int SIZE = 9;
6	int arr [SIZE];
7	cout << "Enter numbers: \n";
8	for (int i = 0; i < SIZE; i++)
9		cin >> arr[i];
10	for (int i = 0; i < SIZE; i++)
11		cout << arr[i] << "\t";
12	cout << endl;
13	cout << "Reversed Array:\n";
14	int temp, start = 0, end = SIZE-1;
15	while (start < end)
16	{
17		temp = arr[start];
18		arr[start] = arr[end];
19		arr[end] = temp;
20		start++;
21		end--;
22	}
23	for (int i = 0; i < SIZE; i++)
24		cout << arr[i] << "\t";
25	cout << endl;	
26  	return 0;
27}
28
Luciano
30 Apr 2019
1#include <iostream>
2#include <algorithm>
3#include <vector>
4#include <iterator>
5using namespace std;
6int main()
7{
8    vector<int>a = {11,22,33,44,99,55};
9    reverse(a.begin(), a.end());
10    auto it = a.begin();
11    for(it= a.begin(); it!=a.end(); it++){
12        cout << *it << ' ';    
13    }
14}
15
Nick
18 Nov 2016
1#include <iostream>
2using namespace std;
3int main()
4{
5	const int SIZE = 9;
6	int arr [SIZE];
7	cout << "Enter numbers: \n";
8	for (int i = 0; i < SIZE; i++)
9		cin >> arr[i];
10	for (int i = 0; i < SIZE; i++)
11		cout << arr[i] << "\t";
12	cout << endl;
13	cout << "Reversed Array:\n";
14	int end = SIZE - 1, temp;
15	for (int i = 0; i < end; i++)
16	{
17		temp = arr[i];
18		arr[i] = arr[end];
19		arr[end] = temp;
20		end--;
21	}
22	/*	Reverse using while loop
23	int temp, start = 0, end = SIZE-1;
24	while (start < end)
25	{
26		temp = arr[start];
27		arr[start] = arr[end];
28		arr[end] = temp;
29		start++;
30		end--;
31	}*/
32	for (int i = 0; i < SIZE; i++)
33		cout << arr[i] << "\t";
34	cout << endl;	
35	}
36
Maya
16 Mar 2018
1//java program to reverse array using for loop
2public class ReverseArrayDemo 
3{
4   public static void main(String[] args) 
5   {
6      int[] arrNumbers = new int[]{2, 4, 6, 8, 10};  
7      System.out.println("Given array: ");  
8      for(int a = 0; a < arrNumbers.length; a++)
9      {
10         System.out.print(arrNumbers[a] + " ");
11      }
12      System.out.println("Reverse array: ");
13      // looping array in reverse order
14      for(int a = arrNumbers.length - 1; a >= 0; a--) 
15      {  
16         System.out.print(arrNumbers[a] + " ");  
17      }
18   }
19}
Matteo
20 May 2019
1#include<iostream>
2using namespace std;
3int main()
4{   
5     int n=3;
6     int arr[]={1,2,3,4};
7      while (n>=0)
8    {
9        cout<<arr[n];
10        n--;
11      }
12         
13    return 0;
14}
queries leading to this page
write a reverse string arraysreversing arra in c 2b 2brevers array in c 2b 2bhow to reverse an int c 2b 2bhow to reverse an int in c 2b 2bsort in reverse order c 2b 2b stlhow to do reverse arrays in c 2b 2breverse c 2b 2breverse sort c 2b 2breverse cpphow to check reverse number in c 2b 2breverse c 2b 2b numberreverse array in c 2b 2b stlreverse method in c 2b 2bhow to reverse an array in c 2b 2b inbuilt functionc 2b 2b sort array reversehow to reverse sort in c 2b 2breverse method of string in javac 2b 2b sort in reversesort reverse c 2b 2b stlstring reverse in javahow to reverse one line of an array in cc 2b 2b reverse 28 29reverse function c 2b 2b complexityhow to reverse the elements of an array c 2b 2breverse sort c 2b 2b algorithmsort mp c 2b 2b in reverse orderreverse array c 2b 2breverse a sting in javaarray reverse cpphow to print string array in reverse order in javasorting array in reverse order c 2b 2bhow to reverse a number in cpphow to reverse array in cppalgorithm to reverse arrayc 2b 2b 2b reverse functionreverse a integer in cppreverse array program c 2b 2breverse array recursionreverse order c 2b 2b arrayreverse queue in c 2b 2breversing array function c 2b 2breverse an array of strings in java without inbuilt functionreverse c 2b 2b programsort reverse cppreverse array codereverse the array geeks for geekshow to reverse a array iin c 2b 2breverse array program c 2b 2breverse function in an array c 2b 2b stlhow to reverse number in c 2b 2b with arrayreverse array fuctionc 2b 2binteger reverse function in c 2b 2breverse array elements c 2b 2breverse algorithm sort c 2b 2breversing elements in an arrayreverses the input array c 2bhow to reverse a string iin javac 2b 2b code to reverse an arrayc 2b 2b backwards returnhow to reverse int in c 2b 2bhow to reverse an array in c 2b 2b using functionreverse arr c 2b 2bhow to reverse an arraycpp reverse 5chow to sort in descending order cppreverse sort algorithm c 2b 2bhow to reverse a array in c 2b 2bjava reverse arraysalgorithm c 2b 2b reverse sortc 2b 2b reverse an arrayhow to reverse sort an array in c 2b 2bget reverse of string javamost efficient way to reverse an array in c 2b 2bwrite a program to reverse an array in c 2b 2barray in reverse order c 2b 2bhow to reverse c 2b 2b how to reverse an array using c 2b 2b stlformua of reverse in c 2b 2bc 2b 2b reverse numberreverse sort cppreverse c 2bsort in descending order c 2b 2b arrayreverse srting in cppreverse an array in cppreverse function in c 2b 2b for array by starting and endingreverse function in c 2b 2b arrayjava string reversereverse functio cppreversing an array in cppreverse function in an array c 2b 2bnumber reverse in cppreverse array c 2bhow to print an array in reverse in c 2b 2breverse aarrayy in c 2b 2breverse string java 27sort i reverse order c 2b 2breverse sort an array in cppreverse array function c 2b 2bc 2b 2b reverse integerprint all the elements of the array in reverse order 2c each element in a new line printing reverse of an array in c 2b 2breverse sorting in c 2b 2brever the arrayc 2b 2b reversereverse 28 29 c 2b 2breversing arrays in cpprevers ann array c 2b 2bhow to reverse a number c 2b 2breverse a statement in c 2b 2bhow to sort an array in reverse order in c 2b 2breverse sort engineering c 2b 2bhow can i reverse a array 3fhow to use reverse function in c 2b 2breverse srting c 2b 2b how to sort in reverse order in c 2b 2barray reverse function in c 2b 2breverse array and stringreverse array elements program in c 2b 2breverse the arrayreverse the order in cppcpp sort backwardsreverse array in cpp stlreverse part of array c 2b 2breverse in cpphow to reverse a string in javareverse the array using function in c 2b 2bhow to reverse a string in java 3fhow to reverse arrayreturn reverse array program c 2b 2bprint array in reverse in c 2b 2bwrite a function that reverses an array in place c 2b 2breverse sort in c 2b 2b stlreverse and array cppsort in reverse in c 2b 2breverse sort an array c 2b 2breverse arrayhow to reverse order of array in c 2b 2breverse int c 2b 2bhow to invert a array in cppreverse array in c 2b 2breverse array algorithm c 2b 2breverse a array in cpp inbuilt functionreverse of array in c 2b 2ba function to output a one dimensional array of size n of integers in reverse order 2c each five values on a separate linecpp array sort backwardshow to reverse arrays c 2b 2bc 2b 2b code to reverse the arrayc 2b 2b algorithm reverse how to sort an array in reverse order in cpp stlreverse function algorithm c 2b 2bc 2b 2b use reverse function for reverse function in c 2b 2bcpp sort descendinghow to reverse of an array using c 2b 2b stlorder array in reverse order c 2b 2bnumber reverse c 2b 2bhow to reverse an array in c 2b 2b using builtin functionreverse c 2b 2b samplereverse function cpprevers an array c 2b 2breverse built in funntion array in c 2b 2bc 2b 2b array reverse orderreverse statement in c 2b 2bsort descending cppc 2b 2b array reversehow to reverse string in javareverse an array in cpp stlreverse string in javainbuild function reverse an array of string in javahow to reverse a integer in cpphow to sort backwards in cpphow to reverse a array in cppinvert an array c 2b 2breversing array in c 2b 2bstring reverse javareverse of interger on c 2b 2b arrayreverse function for array in c 2b 2bhow to reverse the number in c 2b 2bhow to sort elements in array in reverse order in cpparray reverse c 2b 2bhow to reverse an array in c 2b 2breverse c 2b 2breverse an array geeksforgeekswrite a program to reverse an array c 2b 2bcpp reverse array stlreverse a string array in javareverse an int c 2b 2breverse array c 2b 2b functionrevrse an array ireverse in arrayc 2b 2b program to reverse an arrayreverse sort array c 2b 2breverse an array of string in java without inbuilt functionreverse 7 2a7 array c 2b 2breverse int in c 2b 2breverse elements of an arrayreverse a array in c 2b 2breverse an array function in c 2b 2barray reverse in c 2b 2bjava reverse stringrev in cppwrite a function that reverses an array c 2b 2bhow to reverse number using reverse 28 29 in c 2b 2bsort in reverse cpphow to reverse an array at a given no of timefunction to reverse array orderreverse number in c 2b 2b using functionreverse function 5cin c 2b 2breverse array in c 2b 2bstring reverse in javareverse c 2b 2b implementationreverse the array using c 2b 2bhow o reverse array in cpphow to reverse a number on c 2b 2breverse array using stl in c 2b 2bhow to reverse an subarray in cpparray reverse c 2b 2bfunction to reverse an array in cppsort in reverse order c 2b 2bhow to reverse an array in cpp reverse explanation in c 2b 2breverse concatenate javareverse array with c 2b 2bhow to reverse a string in c using 1d arrayreverse inbuilt function in array c 2b 2bhwo to reverse the arraya in c 2b 2barray in descending order c 2b 2breversing an array in c 2b 2banother function of array reversereverse string using java 8inbuilt reverse function in c 2b 2breverse the given array in place using an index and loop rather than a built in function reverse number in an arrayreverse sort an array in javasort function in c 2b 2b reversec 2b 2b reverse arrayreverse list in c 2b 2bsort cpp descendingreverse sort in c 2b 2bc 2b 2b sort array reverse orderc 2b 2b how to reverse an arrayreverse function for array in c 2b 2breverse a integer in cpp stlreverse an array by wherereverse numbers of an arrayhow to reverse an array 3fwrite a program to reverse a string in javac 2b 2b sort reversereverse array algorithmhow to reverse an array in c 2b 2breverse a number cpphow to reverse an integer c 2b 2breverse string javahow to reverse an arrays in c 2b 2bhow to write array in reverse in c 2b 2bjava reverse string arrayc 2b 2b reverse an intreverse sort an array in c 2b 2breverse in c 2b 2breverse an array of integers geeksforgeeksreverse of a number using function in cppreverse 28 29 in c 2b 2breverse array in cppreverse array cppreverse a int array in c 2b 2breverse in c 2b 2b stlreversal of arrayhow to sort reverse in c 2b 2bc 2b 2b how to reverse a intprint reverse array in c 2b 2bsort array reverse in c 2b 2bhow to sort array in descending order in c 2b 2b using reversereversing array c 2b 2breverse sort arr c 2b 2bstring reverse method javac 2b 2b reverse listsort e reverse c 2b 2breverwse an array c 2b 2breverse 28 29 in cppreverse sort an array methods in cpparray element reverse in c 2b 2breverse array in creverse sort array in c 2b 2bsort c 2b 2b reversereverse an array algorithmhow to reverse an array in placehow to print reverse an array in c 2b 2bhow to reverse the integer in cppreverse java stringfunction in c 2b 2b to reverse an arrayreverse function c 2b 2bhow to sort in reverse order using sort in c 2b 2bhow to use reverse in c 2b 2bjava create a function reverses stringc 2b 2b reverse number functionhow to reverse in cppin place array reversalhow to reverse an array c 2b 2bhow to reverse an array in c 2b 2b 3bhow to reverse sort a array c 2b 2bhow to reverse an integer in c 2b 2breverse function array c 2b 2bhow o reverse array in cpp stlreverse function c 2b 2b referencesort array reverse c 2b 2bc 2b 2b to reverse an arrayreverse an array cpprevers the arrayshow to display a string backwards javac 2b 2b how to reverse an intreverse a array c 2b 2breversing a array c 2b 2breverse string program in javareverse an array in c 2b 2b stl reverse of an array in c 2b 2breversing an array i c 2b 2breverse an integer c 2b 2bc 2b 2b reverse codefunction to reverse an arrayreverse an array in c 2b 2brever the arr in c 2b 2breverse a integet c 2b 2bstl reverse an array cpp16 29 write a program to do reverse arraysudo code to reverse an arraysort descending order cppreverse an array or stringreverse elements in an array stl reverse array in c 2b 2breverse an arrays c 2b 2b user definedwrite algorithm which will reverse array 2c without using std toolshow to reverse array in c 2b 2breverse a part of array c 2b 2breverse array in c 2b 2breverse a number in cppc 2b 2b reverseprint array in reverse order try solving this using recursionhpw to reverse an array in placehow does reverse function in c 2b 2b work inbuiltreverse string array javareversing an arrayreverse of an array c 2b 2bhow to reverse a array in c 2b 2bfunction to reverse an array in cpp stlreverse a array in cppreverse a part of an array in cppprint array in reverse order note 3a try solving this using recursionreverse the elements of array between two points c 2b 2bhow to print an array in reverse order in c 2b 2breverse array cc 2b 2b reverse intreverse in c 2breverse string elements in an arrayc 2b 2b reverse functionhow to reverse the array in c 2b 2bhow to reverse a string in c using 1d array using for loopsinbuilt function to reverse an array in c 2b 2bcan we use reverse on int array in c 2b 2breversearray functionwrite c 2b 2b program to reverseprogram to reverse an array c 2b 2breverse of array c 2b 2breverse string in java nreverse elements of array c 2b 2breverse a subarray in an array c 2b 2bc 2b 2b stl reverse sortto reverse arrays c 2b 2breverse arrajava how to reverse stringreverse of interger on c 2b 2bsort array in descending order c 2b 2bwhat is reverse function in c 2b 2bhow to reverse a number in c 2b 2breverse of an array c 2b 2b with newprogram to reverse the elements of an array in c 2b 2breverse an array method cpprevrse an array c 2b 2breversing an array in c 2b 2b functionreverse operation in c 2b 2bprogram to reverse an array in c 2b 2breverse string geeksforgeekscpp sort int array reversecpp get reverse of arayc 2b 2b reverse methodint reverse function c 2b 2b1234 is an array u have to revserfuntion to reverse a array in c 2b 2breverse c 2b 2b stl arrayreverse an array function in c 2b 2b loopreverse the elements of array in c 2b 2bc 2b 2b reverse array functionhow to reverse sort a array in c 2b 2bhow to sort in reverse in c 2b 2b using sortreverse strings in an array javareverse array fuction c 2b 2bhow to sort an array in reverse order in cpphow to reverse an arr in cppreverse integer cppc 2b 2b htons reversehow to reverse array c 2b 2breturn a reversed array as a functionreverse function in c 2b 2b for arrayreverse an array in c 2b 2b simplereverse a in c 2b 2brevers array string javareverse the array in c 2b 2breverse an array c 2b 2b stlhow to reverse a arrayreverse an array stl c 2b 2breverse in c 2b 2b arrayreverse an arry c 2b 2breverse intege c 2b 2breverse integer in cpphow to sort array in reverse order in c 2b 2bsort array descending c 2b 2bsort array in descending order cppreverse a arrar in cppalgorithm c 2b 2b reveres sortreverse function in c 2b 2bsorting reverse c 2b 2breverse an array in c 2b 2b algorithmshow to print an array in reverse orderreverse an array in c 2b 2b inbuilt functionjava how to reverse a stringc 2b 2b stl reverse arrayfastest way to reverse an array c 2b 2breverse array stringsreverse arrayc 2b 2breverse int array c 2b 2breverse array in c 2b 2b stlreverse the array in c 2b 2b library functionreverse a number function in c 2b 2breverse an array of string in javahow to create a reverse array from a given array in c 2b 2breverse of number in cpprevesrse arrayreverse of an arrayhow to get reverse value in c 2b 2breverseing string in javareverse an array in csort in reverse c 2b 2breverse function cpp stlfind 28 29 from reverese c 2b 2bhow to reverse an array cpparray reverse in cppjava string reverse functionhow to reverse sort an array in c 2b 2b using stltermination of reverse array algorithm explanationreverse to string javareverse funtion in c 2b 2bhow to reverse an array in c 2b 2b stlreverse function in array in c 2b 2bcpp program to reverse an arrayreverse array using cpphow to sort array descending in c 2b 2breverse array elementsreverse array function in c 2b 2bjava program to reverse a stringc 2b 2b std reverse arrayreverse node function c 2b 2breverse function in cppreverse a no in c 2b 2bc 2b 2b how to reversereverse an arraywhat is the build in function reverse in c 2b 2breverse function in c 2breverse an array inplacereverse array c 2b 2b stlhow to reverse an array in c 2b 2b using stlsort and reverse c 2b 2breverse tsack function in c 2b 2breverse 28 29 array c 2b 2breverse c 2b 2b arrayreverse a string in javac 2b 2b sort array descendinghow can i reverse an integar with c 2b 2bcpp reverse arraypass reverse array c 2b 2breverse order array cpphow to reverse an integer in cppalgorithm to reverse an arrayreverse function in array c 2b 2bc 2b 2b reverse litsorting in reverse order cppreverse in c 2b 2b array in built functionreverse of array in c 2b 2b reverse in c 2b 2bsort array in reverse order c 2b 2breverse the array in c 2b 2b 3fis reverse sorted cppreverse or cppstring reverse method in javac 2b 2b reverse array stlreverse sorting an array in c 2b 2breverse function of array in cppreverse the elements of array in place cppreverse array javainvert an array cppc 2b 2b reverse array algorithmdisplay an array in reverse order in c 2b 2bjava reverse array methodreverse a number in c 2b 2breverse an array c 2b 2breverse an array in cpp