diff --git a/hacker-rank/algorithms/sorting/Mark and Toys/Mark and Toys.cpp b/hacker-rank/algorithms/sorting/Mark and Toys/Mark and Toys.cpp new file mode 100644 index 0000000..4329790 --- /dev/null +++ b/hacker-rank/algorithms/sorting/Mark and Toys/Mark and Toys.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; + +int main() { + int n,x,s=0; + std::vector v; + cin>>n>>x; + int a[n]; + for(int i=0;i>a[i]; + } + sort(a,a+n); + for(int i=0;ix) + { + break; + } + v.push_back(a[i]); + } + cout< +#include +using namespace std; + +void bubble_sort(int a[],int n) +{ + int flag,p=0; + for(int i=0;ia[j+1]) + { + swap(a[j],a[j+1]); + flag=1; + p++; + } + } + if(flag==0) + { + break; + } + } + + cout<<"Array is sorted in"<<" "<>n; + int a[n]; + for(int i=0;i>a[i]; + } + bubble_sort(a,n); + return 0; +} + + +// Input: +// 4 +// 3 12 4 2 +// Output: +// Array is sorted in 4 swaps. +// First Element: 2 +// Last Element: 12