You have unread notifications. Click here.

Divide and Conquer 2

Loading ...
Start Coding
#include <iostream>
#include <vector>
using namespace std;
void conqure (vector<int> &x, int s1, int e1, int s2, int e2){
-vector<int> r;
-int s = s1;
-while(s1<=e1 && s2<=e2)
--if(x[s1]< x[s2])
---r.push_back(x[s1++]);
--else
---r.push_back(x[s2++]);
-while(s1<=e1)
--r.push_back(x[s1++]);
-while(s2<=e2)
--r.push_back(x[s2++]);
-for(int i=0; i<r.size(); i++,s++)
--x[s] = r[i];
}
void divide(vector<int> &x, int s, int e){
-if(s==e)
--return;
-int s1 = s, e1 = (s+e)/2 ;
-int s2 = e1+1 , e2 = e;
-divide(x, s1, e1);
-divide(x, s2, e2);
-return conqure(x, s1, e1, s2, e2);
}
int main() {
-vector<int> x={4,3,9,8,6};
-divide(x,0,(int)x.size()-1);
-for(int i=0; i<x.size(); i++)
--cout<<x[i]<<endl;
-return 0;
}

Exercises

English Version

. A program that  calculates the power using (a base number and an exponent)


Show Advanced Exercises

Advanced Exercises

Questions

Answer the following questions according to what you learned from the video.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Send

Comments & Feedback

ملحوظة يتم مراجعة التعليقات قبل ظهورها من قبل الإدارة. رجاء عدم كتابة نفس التعليق أكثر من مرة.
Back to Course