How To Reverse an Array in C++ (Multiple Approaches) (Hindi) | Arrays

preview_player
Показать описание
How To Reverse an Array in C++(Multiple Approaches)(Hindi) | Arrays

Hi
Welcome To our channel Code Bashers.

About Video:
In this video i have discussed different approaches for reversing an array. First approach is to make a new array and traverse the input array for behind , while traversing the array put each element in the new array and when the traversal is complete return the new array. Second approach is the two pointer approach where in we declare two variables , initialise one with 0 index and other with index n-1, now we will swap the values of this pointer and then increment the start pointer and decrement the end pointer and when start becomes greater than or equal to end our loops break.
See video for explanation with example and dry run.

Queries Covered in this video:
1) Approach to reverse the array.
2) Complexity Discussion for different approaches used to reverse array.
3) code for reversing the array.

Complexity Discussion:
Approach 1:
space complexity = O(N)
time complexity = O(N)

Approach 2:
space complexity = O(1)
time complexity = O(N)

#reversearray #arrays #code

Please Like , Share , Subscribe and forward it to your friends.

Thank You

Links to previous videos:
Find Second Largest Number in an Array(Multiple Approaches)(Hindi) || Array Data Structure:

find minimum and maximum value in array C++ | Arrays:

About Channel:
Our channel make videos related to programming. I hope my content helps you land the job of your dreams and become a better engineer!
Рекомендации по теме
Комментарии
Автор

thank you so much sir I've been watching 5 videos about the topic on youtube But I got The best explanation after watching your video

thefourhourtalk
Автор

#include<iostream.h>
using namespace std;

int reversArray(int arr[], int start, int end){

if(start>=end){
return; //Base case
}

swap(arr[start], arr[end]); //small calcul

reversArray( arr, start+1, end-1); // recursive call
}
int printArray( int arr[], int size){
for(int i =0; i<n; i++){
cout<<arr[i]<<" ";
}
}

ap_information
Автор

Great efforts and nice explanation sir 😊
Sir provide the video for binary search and questions also.
Thank you

ashishchhabra
Автор

# include <iostream>
using namespace std;

int main()
{
int size_array;
cout<<"Size : ";
cin>>size_array;

int array[size_array];

for (int i = 0 ; i < size_array ; i++)
{
cin>>array[i];
}

int s = 0;
int e = size_array - 1;

while (s < size_array)
{
swap(array[s], array[e]);
s++;
e--;
}

for (int x = 0 ; x < size_array ; x++)
{
cout<<array[x]<<" "<<endl;
}

}



what am i doing worng???

kffootball
Автор

swap function kaha se laaya bro tu
C++ me inbuilt hai kya ?

sparshkhandelwal
Автор

Mera to ni kia yh run .. swap function prewrttieen wale se kaam ni banta tune khud likha he kya upar ? . .

geekysunny