MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / reverse2

Function reverse2

A-Array/Reversingofarray.cpp:35–43  ·  view source on GitHub ↗

1. Using high and low pointers we can initialize two poinetrs high and low and swapping arr[low] with arr[high] with reverse our main array(arr) without using any auxuliaary array*/

Source from the content-addressed store, hash-verified

33/* 1. Using high and low pointers
34 we can initialize two poinetrs high and low and swapping arr[low] with arr[high] with reverse our main array(arr) without using any auxuliaary array*/
35void reverse2(int arr[], int n)
36{
37 for (int low = 0, high = n - 1; low < high; low++, high--) {
38 swap(arr[low], arr[high]); //swapping the elements from wiht the help of high and low pointers
39 }
40
41 //Time-Complexity-->O(n) where n is the total number of elements in array
42//space-complexity-->O(1) -->Constant
43}
44
45
46int main()

Callers 1

mainFunction · 0.85

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected