Merge Sort under 4 mins | Visualization with animation | Coddict

preview_player
Показать описание
Recursive in nature, merge sort divides an array in half repeatedly until it can no longer be divided, meaning that it is left with just one element (an array containing one element is always sorted). One sorted array is then created by merging the sorted subarrays.

Find the code snippet in the pinned comment.

Like, share, and subscribe to show your support.. It matters as you matter..

Music license info:

Рекомендации по теме
Комментарии
Автор

Code snippet:

void merge(vector<int>&arr, int l, int mid, int r){
int leftLength=mid-l+1;
int rightLength=r-mid;
vector<int> leftSubArray(leftLength), rightSubArray(rightLength);
int j=0;
for(int i=l;i<=mid;i++)
leftSubArray[j++]=arr[i];
j=0;
for(int i=mid+1;i<=r;i++)
rightSubArray[j++]=arr[i];

int leftInd=0, rightInd=0, ind=l;
while(leftInd<leftLength && rightInd<rightLength){


ind++;
leftInd++;
}
else{

ind++;
rightInd++;
}
}
while(leftInd<leftLength){

}
while(rightInd<rightLength){

}
}
void mergeSort(vector<int>&arr, int l, int r){
if(l>=r){
return;
}
int mid=l+(r-l)/2;
mergeSort(arr, l, mid);
mergeSort(arr, mid+1, r);
merge(arr, l, mid, r);
}

coddict
Автор

continue doing the hard work one day you will get the result back.

MrSagarBiswas
Автор

How do you create this video? Thank u.

a-wzdo
Автор

Nice fucking music but fully irritating while Focusing seriously 😒

lakshmipathig