From 0f0af7f4c104ba9a80949e4bdd3d7ecf3dd67007 Mon Sep 17 00:00:00 2001 From: Sharmistha Mandal <65134125+Sharmi-1999@users.noreply.github.com> Date: Sat, 3 Oct 2020 01:50:48 +0530 Subject: [PATCH] Add files via upload --- .../sorting/Mark and Toys/Mark and Toys.cpp | 33 +++++++++++ .../Sorting_Bubble Sort.cpp | 55 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 hacker-rank/algorithms/sorting/Mark and Toys/Mark and Toys.cpp create mode 100644 hacker-rank/algorithms/sorting/Sorting_Bubble Sort/Sorting_Bubble Sort.cpp 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