forked from dscmsit/Problem-Solving-in-any-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseTwopointer.cpp
More file actions
36 lines (36 loc) · 796 Bytes
/
reverseTwopointer.cpp
File metadata and controls
36 lines (36 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// To reverse array of given data using two poiter approach
// Created by Vatsal Jha on 12th October 2022
#include <iostream>
using namespace std;
void reverseArray(int arr[], int n)
{
int s = 0;
int e = n - 1;
while (s <= e)
{
int temp = arr[s];
arr[s] = arr[e];
arr[e] = temp;
s++;
e--;
}
cout << "after reversing" << endl;
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int k = sizeof(arr) / sizeof(int);
cout << "before reversing=" << endl;
for (int i = 0; i < k; i++)
{
cout << arr[i] << " ";
}
cout << endl;
reverseArray(arr, k);
return 0;
}