{"id":85,"date":"2020-05-20T19:00:42","date_gmt":"2020-05-20T19:00:42","guid":{"rendered":"http:\/\/sites.tntech.edu\/acrockett\/?p=85"},"modified":"2020-05-20T19:01:28","modified_gmt":"2020-05-20T19:01:28","slug":"bubble-sort","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/acrockett\/2020\/05\/20\/bubble-sort\/","title":{"rendered":"Bubble Sort"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Problem Description<\/h2>\n\n\n\n<p>Place elements organized in an array or list in either ascending or descending order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Algorithm Description<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"232\" src=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort-1024x232.png\" alt=\"\" class=\"wp-image-92\" srcset=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort-1024x232.png 1024w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort-300x68.png 300w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort-768x174.png 768w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort-1536x347.png 1536w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble_sort.png 1662w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Bubble sort is a simple sorting algorithm that repeatedly steps through the list or array to be sorted, compares each pair of adjacent items, and swaps them if they are in the wrong order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Videos<\/h2>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Sorting Algorithms - Chapter 1 - Bubble Sort 3D Animation\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/NiyEqLZmngY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Bubble-sort with Hungarian (&quot;Cs\u00e1ng\u00f3&quot;) folk dance\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/lyZQPjUT5B4?start=73&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Bubble Sort | GeeksforGeeks\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/nmhjrI-aW5o?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Bubble Sort\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/Cq7SMsQBEUw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Going through Bubble Sort with Actual Input<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1013\" height=\"1024\" src=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1-1013x1024.png\" alt=\"\" class=\"wp-image-90\" srcset=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1-1013x1024.png 1013w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1-297x300.png 297w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1-768x776.png 768w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1-1520x1536.png 1520w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/bubble-sort-example-1.png 1635w\" sizes=\"auto, (max-width: 1013px) 100vw, 1013px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">C++ Code<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nvoid displayArray(int*, int);\nvoid bubbleSort(int*, int);\n\nint main(){\n\tint myArr&#091;5] = {85, 42, 7, 186, 18};\n\tdisplayArray(myArr, 5);\n\tbubbleSort(myArr, 5);\n\tdisplayArray(myArr, 5);\n\treturn 0;\n}\nvoid bubbleSort(int *arr, int size){\n\tint tempForSwap;\n\tcout &lt;&lt; \"\\nSorting the array with the Bubble Sort algorithm.\\n\\n\";\n\t\/\/maxElement will hold the subscript of the last element \n\t\/\/that is to be compared to its immediate neighbor\n\tfor(int maxElement=(size-1); maxElement &gt; 0; maxElement--){\n\t\tfor(int i=0; i&lt;maxElement; i++) {\n\t\t\tif(arr&#091;i] &gt; arr&#091;i+1]) { \/\/swap!\n\t\t\t\ttempForSwap = arr&#091;i];\n\t\t\t\tarr&#091;i] = arr&#091;i+1];\n\t\t\t\tarr&#091;i+1] = tempForSwap;\n\t\t\t}\n\t\t}\n\t}\n}\nvoid displayArray(int *arr, int size){\n\tcout &lt;&lt; \"\\n--------------------The array:  \";\n\tfor(int i=0; i&lt;size; i++){\n\t\tcout &lt;&lt; arr&#091;i] &lt;&lt; \" \";\n\t}\n\tcout &lt;&lt; \"--------------------\\n\";\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Other Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>GeeksforGeeks: <a href=\"https:\/\/www.geeksforgeeks.org\/bubble-sort\">https:\/\/www.geeksforgeeks.org\/bubble-sort<\/a><\/li><li>Programiz: <a href=\"https:\/\/www.programiz.com\/dsa\/bubble-sort\">https:\/\/www.programiz.com\/dsa\/bubble-sort<\/a><\/li><li>Visualgo (Visualization of Bubble Sort): <a href=\"https:\/\/visualgo.net\/bn\/sorting?slide=6\">https:\/\/visualgo.net\/bn\/sorting?slide=6<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description Place elements organized in an array or list in either ascending or descending order. Algorithm Description Bubble sort is a simple sorting algorithm that repeatedly steps through the list or array to be sorted, compares each pair of adjacent items, and swaps them if they are in the wrong order. Videos Going through [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[9,11,10],"class_list":{"0":"post-85","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-algorithms","7":"tag-algorithm","8":"tag-bubble-sort","9":"tag-sort-algorithm","10":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/comments?post=85"}],"version-history":[{"count":4,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/85\/revisions"}],"predecessor-version":[{"id":94,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/85\/revisions\/94"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/media?parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/categories?post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/tags?post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}