{"id":38008,"date":"2016-10-14T17:21:02","date_gmt":"2016-10-14T22:21:02","guid":{"rendered":"http:\/\/danigguemez.wordpress.com\/?p=432"},"modified":"2016-10-14T17:21:02","modified_gmt":"2016-10-14T22:21:02","slug":"bubble-sort","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/bubble-sort\/","title":{"rendered":"Bubble sort"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/danigguemez.wordpress.com\/2016\/10\/14\/bubble-sort\/\"><a href=\"https:\/\/danigguemez.wordpress.com\">Fundamentos de Programaci\u00f3n<\/a><\/a><\/em><br \/><\/p>\n<p>Just like the previous challenge, this time we had to put a list in order but instead of using random we use the bubble sort method (thanks God!).<\/p>\n<p><img class=\"alignnone size-full wp-image-435\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/rw9ykew_700wa_0.gif?w=676\" alt=\"rw9ykew_700wa_0\"   \/><\/p>\n<p>It is so much better and efficient, in contrast with random, also it is less code so if you want to do it the better way&#8230;.. don&#8217;t use any of this, there is a built in function in python that does it for you hehe<\/p>\n<p><img class=\"alignnone size-full wp-image-439\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/krqrjmd_700wa_0.gif?w=676\" alt=\"krqrjmd_700wa_0\"   \/><\/p>\n<p>Don&#8217;t go! it&#8217;s still usefull to know this way of sorting. Here it is:<\/p>\n<p><img class=\"alignnone size-full wp-image-444\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/bubble1.png?w=676\" alt=\"bubble1\"   \/><\/p>\n<p>The same as the random code except that instead of sorting asigning random index we use the function bubble(). This function, while the list is not sorted, compares each pair of numbers that are side by side in the list and if the first one is greater than the second one it swiches the position of those numbers.<\/p>\n<p><img class=\"alignnone size-full wp-image-447\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/xw7v9db_700w_0.jpg?w=676\" alt=\"xw7v9db_700w_0\"   \/><\/p>\n<p>The rest is just printing the list an the amount of times the while repeated. Hava a look to the results to compare the difference between this and random sorting:<\/p>\n<p><img class=\"alignnone size-full wp-image-450\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/bubble2.png?w=676\" alt=\"bubble2\"   \/><\/p>\n<p>And with 10 numbers:<\/p>\n<p><img class=\"alignnone size-full wp-image-451\" src=\"https:\/\/danigguemez.files.wordpress.com\/2016\/10\/bubble3.png?w=676\" alt=\"bubble3\"   \/><\/p>\n<p>Big difference.<\/p>\n<p>Here is a video to help you out:<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe class='youtube-player' type='text\/html' width='676' height='411' src='https:\/\/www.youtube.com\/embed\/8Kp-8OGwphY?version=3&#038;rel=1&%23038;fs=1&%23038;autohide=2&%23038;showsearch=0&%23038;showinfo=1&%23038;iv_load_policy=1&%23038;wmode=transparent' allowfullscreen='true' style='border:0;'><\/iframe><\/div>\n<p>Follow me on twitter <a href='https:\/\/danigguemez.wordpress.com\/mentions\/danigguemez\/' class='mention'><span class='mentions-prefix'>@<\/span>danigguemez<\/a><\/p>\n<p>Code avaliable in Github:\u00a0https:\/\/github.com\/Guemez\/TC1014\/blob\/master\/bubblesort.py<\/p>\n<p>#TC101 #python #bubblesort #DailyChallenge<\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/danigguemez.wordpress.com\/432\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/danigguemez.wordpress.com\/432\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=danigguemez.wordpress.com&#038;blog=115238226&%23038;post=432&%23038;subd=danigguemez&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Fundamentos de Programaci\u00f3n Just like the previous challenge, this time we had to put a list in order but instead of using random we use the bubble sort method (thanks God!). It is so much better and efficient, in contrast with random, also it is less code so if you want to &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/bubble-sort\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bubble sort<\/span><\/a><\/p>\n","protected":false},"author":8,"featured_media":435,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[28],"class_list":["post-38008","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-uncategorized"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=38008"}],"version-history":[{"count":4,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38008\/revisions"}],"predecessor-version":[{"id":40701,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38008\/revisions\/40701"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=38008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=38008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=38008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}