diff --git a/medium/day_1/solution.cpp b/medium/day_1/solution.cpp index 4763798..4762c32 100644 --- a/medium/day_1/solution.cpp +++ b/medium/day_1/solution.cpp @@ -1 +1,50 @@ -//Write your solution here \ No newline at end of file +//Write your solution here +//Write your solution here +// CODE BY JAGPREET153 + +#include +using namespace std; + +void add(vector& v, int temp) { // Function for adding the element inside the vector + if (v.empty() ||v.back()<=temp) { // if vector is empty or last element is less than the temp + v.push_back(temp); + return; + } + int value = v[v.size()-1]; + v.pop_back(); + add(v, temp); + v.push_back(value); +} + +void sorting(vector& v) { + if (v.size() == 1) // if vector size is 1 + return; + int temp=v.back(); + v.pop_back(); // pop the last element + sorting(v); + add(v, temp); // add the last element in the vector +} + +// first we will sort the vector by popping the last element and then calling the sorting function again and again till the size of vector is 1 +// and then we will insert the last element in the vector after checking tha last element is greater than the temp or not +int main() { + int n,i,x,t; + cin>>t; + while(t--) + { + cin >> n; + vector v; + for (i=0;i>x; + v.push_back(x); + } + sorting(v); // Sorting the vector + for (int i=0;i