-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf37bdf
commit 4996794
Showing
25 changed files
with
35 additions
and
35 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,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; | ||
// 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; | ||
} |