From f2e344c9ee96c9009f541b95d14fb2981d8ecf89 Mon Sep 17 00:00:00 2001 From: abdurrezzak Date: Tue, 24 Oct 2017 01:52:41 +0300 Subject: [PATCH] Add files via upload --- 6.BubbleSort.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 6.BubbleSort.cpp diff --git a/6.BubbleSort.cpp b/6.BubbleSort.cpp new file mode 100644 index 0000000..8c1fc3e --- /dev/null +++ b/6.BubbleSort.cpp @@ -0,0 +1,37 @@ +/* + * This program takes an array from the user + * sorts it using bubble sort + * Prints the sorted array + * For more information about Bubble Sort Algorithm: https://en.wikipedia.org/wiki/Bubble_sort + * + * Coded by: Abdurrezak EFE + * + * */ +#include +#include +using namespace std; + +void bubble_sort(int arr[],int k) //bubble sort function +{ + int i, j,temp; + for (i = 0; i < k-1; i++) + for (j = 0; j < k-i-1; j++) + if (arr[j] > arr[j+1]) + temp=arr[j],arr[j]=arr[j+1],arr[j+1]=temp; //swapping +} + +int main() +{ + int k; + cout << "Enter the number of the integers you want to construct the array from: "; + cin >> k; + + int arr[k]; + for(int i=0;i> arr[i]; + + bubble_sort(arr,k); //sorting + + for(int i=0;i