{"id":403,"date":"2016-08-01T13:59:54","date_gmt":"2016-08-01T11:59:54","guid":{"rendered":"http:\/\/www.hunggartorino.it\/ql\/?p=403"},"modified":"2016-05-13T14:41:18","modified_gmt":"2016-05-13T12:41:18","slug":"the-sorting-numbers-routines","status":"publish","type":"post","link":"http:\/\/www.hunggartorino.it\/ql\/the-sorting-numbers-routines\/","title":{"rendered":"The sorting numbers routines"},"content":{"rendered":"<p class=\"tw-data-text vk_txt tw-ta tw-text-small\" dir=\"ltr\" data-placeholder=\"Traduzione\"><span lang=\"en\">A classic of programming required in the industrial technical schools is the realization of the so-called <em>bubble sort<\/em> : comparing two numbers so that the smallest &#8220;leaps&#8221; in the upper position. It can be realized with a pair of cycles and a temporary variable (as support ) that allows the exchange of the array values, thus avoiding the loss of one of the two numbers.<br \/>\nWith SuperBasic to sort in ascending order we&#8217;ll proceed in this way:<\/span><\/p>\n<div><\/div>\n<blockquote>\n<div>240 FOR I = A-1 TO 1 STEP -1<\/div>\n<div>250 FOR J = 0 TO I \u2013 1<\/div>\n<div>260 IF matrice$(J)&gt;matrice$(J+1) THEN<\/div>\n<div>270 Temp$ = matrice$(J)<\/div>\n<div>280 matrice$(J) = matrice$(J+1)<\/div>\n<div>290 matrice$(J+1) = Temp$<\/div>\n<div>300 END IF<\/div>\n<div>310 NEXT J<\/div>\n<div>320 NEXT I<\/div>\n<\/blockquote>\n<div><\/div>\n<div>\n<p id=\"tw-target-text\" class=\"tw-data-text vk_txt tw-ta tw-text-small\" dir=\"ltr\" data-placeholder=\"Traduzione\"><span lang=\"en\">while the reverse order (highest to lowest ) is so made:<\/span><\/p>\n<\/div>\n<div><\/div>\n<blockquote>\n<div>340 FOR I = A-1 TO 1 STEP -1<\/div>\n<div>350 FOR J = 0 TO I \u2013 1<\/div>\n<div>360 IF matrice$(J)&lt;matrice$(J+1) THEN<\/div>\n<div>370 Temp$ = matrice$(J)<\/div>\n<div>380 matrice$(J) = matrice$(J+1)<\/div>\n<div>390 matrice$(J+1) = Temp$<\/div>\n<div>400 END IF<\/div>\n<div>410 NEXT J<\/div>\n<div>420 NEXT I<\/div>\n<\/blockquote>\n<div><\/div>\n<div>\n<p id=\"tw-target-text\" class=\"tw-data-text vk_txt tw-ta tw-text-small\" dir=\"ltr\" data-placeholder=\"Traduzione\"><span lang=\"en\">So, the implementation on the QL is similar to what also happens with the other Basic dialects except from the END IF statement which, for example, is missing in ZX Spectrum Basic and therefore is necessary to use GOSUBs or set all on the same line. As well is missing the ELSE keyword, so we have to utilize jumps thus making the program less clear.<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"A classic of programming required in the industrial technical schools is the realization of the so-called bubble sort : comparing two numbers so \n<a class=\"moretag\" href=\"http:\/\/www.hunggartorino.it\/ql\/the-sorting-numbers-routines\/\"> [..more...]<\/a>","protected":false},"author":2,"featured_media":313,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"_links":{"self":[{"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":3,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"predecessor-version":[{"id":691,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/posts\/403\/revisions\/691"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/media\/313"}],"wp:attachment":[{"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hunggartorino.it\/ql\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}