{"id":691,"date":"2016-12-29T08:51:27","date_gmt":"2016-12-29T06:51:27","guid":{"rendered":"http:\/\/ersinakyuz.com\/blog\/?p=691"},"modified":"2016-12-29T08:51:27","modified_gmt":"2016-12-29T06:51:27","slug":"bubble-sorting-with-perl","status":"publish","type":"post","link":"https:\/\/www.ersinakyuz.com\/?p=691","title":{"rendered":"Bubble sorting with Perl"},"content":{"rendered":"<pre class=\"\">#!\/usr\/bin\/perl \r\nuse strict;\r\nuse Data::Dumper;\r\n\r\nsub swap{\r\n\u00a0 \u00a0 \u00a0@_[ 0, 1 ] = @_[ 1, 0 ];\r\n}\r\n\r\nsub bsort{\r\n\u00a0 \u00a0 \u00a0my (@a) = @_;\r\n\u00a0 \u00a0 \u00a0for my $j (0 .. $#a){\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for my $i (0 .. $#a - 1 - $j ){\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 swap $a[$i], $a[ $i + 1 ] if $a[$i] &gt; $a[ $i + 1 ];\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}\r\n\u00a0 \u00a0 \u00a0}\r\n \\@a;\r\n }\r\n\r\n\r\n\r\n#Testing\u00a0\r\nmy $a=1;\r\nmy $b=3;\r\nmy @c=(3,2,1,4);\r\nprint \"First:\".Dumper(@c);\r\nprint \"\\nLatest:\".Dumper(bsort(@c));<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/perl use strict; use Data::Dumper; sub swap{ \u00a0 \u00a0 \u00a0@_[ 0, 1 ] = @_[ 1, 0 ]; } sub bsort{ \u00a0 \u00a0 \u00a0my (@a) = @_; \u00a0 \u00a0 \u00a0for my $j (0 .. $#a){ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for my $i (0 .. $#a &#8211; 1 &#8211; $j ){ \u00a0 \u00a0 \u00a0 \u00a0 &#8230; <a title=\"Bubble sorting with Perl\" class=\"read-more\" href=\"https:\/\/www.ersinakyuz.com\/?p=691\" aria-label=\"Read more about Bubble sorting with Perl\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[33],"class_list":["post-691","post","type-post","status-publish","format-standard","hentry","category-programming","tag-perl"],"_links":{"self":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=691"}],"version-history":[{"count":1,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/691\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/691\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}