{"id":20646,"date":"2019-12-09T17:45:25","date_gmt":"2019-12-09T16:45:25","guid":{"rendered":"http:\/\/www.valcon.it\/pp\/?p=20646"},"modified":"2024-06-17T19:25:02","modified_gmt":"2024-06-17T17:25:02","slug":"ordinare-4","status":"publish","type":"post","link":"https:\/\/www.valcon.it\/pp\/ordinare-4\/","title":{"rendered":"Ordinare 4 dati"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Con <strong>6<\/strong> confronti\/scambi<\/h2>\n\n\n\n<p><em>Prova con i numeri<\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\n+-----+-----+-----+-----+\n|  x1 |  x2 |  x3 |  x4 |\n+-----+-----+-----+-----+------------+\n| 100 |  10 |  -8 | -25 | (x1 &gt; x2)? | 100 sale di posizione\n|  10 | 100 |  -8 | -25 | (x2 &gt; x3)? | ...\n|  10 |  -8 | 100 | -25 | (x3 &gt; x4)? | ... \n|  10 |  -8 | -25 | 100 | (x1 &gt; x2)? | 100 ha raggiunto la posizione definitiva\n|  -8 |  10 | -25 | 100 | (x2 &gt; x3)? | 10 sale di posizione\n|  -8 | -25 |  10 | 100 | (x1 &gt; x2)? | 10 ha raggiunto la posizione definitiva\n| -25 |  -8 |  10 | 100 |            | -8 ha raggiunto la posizione definitiva\n+-----+-----+-----+-----+------------+ In 1\u00b0 posizione rimane il valore minimo!\n<\/pre><\/div>\n\n\n<p>La sequenza di confronti (e scambi) segue l&#8217;algoritmo <a href=\"http:\/\/www.valcon.it\/pp\/bubble-sort\/\">Bubble Sort<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Codifica Pascal<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nIf x1 &gt; x2 Then\n    Begin\n        temp:=x1  ;\n        x1  :=x2  ;\n        x2  :=temp;\n    End;\nIf x2 &gt; x3 Then\n    Begin\n        temp:=x2  ;\n        x2  :=x3  ;\n        x3  :=temp;\n    End;\nIf x3 &gt; x4 Then \n    Begin \n        temp:=x3  ;\n        x3  :=x4  ;\n        x4  :=temp; \n    End;\nIf x1 &gt; x2 Then\n    Begin\n        temp:=x1  ;\n        x1  :=x2  ;\n        x2  :=temp;\n    End;\nIf x2 &gt; x3 Then\n    Begin\n        temp:=x2  ;\n        x2  :=x3  ;\n        x3  :=temp;\n    End;\nIf x1 &gt; x2 Then\n    Begin\n        temp:=x1  ;\n        x1  :=x2  ;\n        x2  :=temp;\n    End;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Con <strong>5<\/strong> confronti\/scambi<\/h2>\n\n\n\n<p><em>Prova con i numeri<\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\n+-----+-----+-----+-----+\n|  x1 |  x2 |  x3 |  x4 |\n+-----+-----+-----+-----+------------+\n| 100 |  -8 |  10 | -25 | (x1 &gt; x2)? |\n|  -8 | 100 |  10 | -25 | (x3 &gt; x4)? |\n|  -8 | 100 | -25 |  10 | (x1 &gt; x3)? | \n| -25 | 100 |  -8 |  10 | (x2 &gt; x4)? | \n| -25 |  10 |  -8 | 100 | (x2 &gt; x3)? | \n| -25 |  -8 |  10 | 100 |            | \n+-----+-----+-----+-----+------------+\n<\/pre><\/div>\n\n\n<p>Ci sono 4 valori da ordinare<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\n+----+----+----+----+\n| x1 | x2 | x3 | x4 | Prima\n+----+----+----+----+\n| r1 | r2 | r3 | r4 | Dopo\n+----+----+----+----+\n\n+----+----+----+----+------------+\n| x1 | x2 | x3 | x4 | (x1 &gt; x2)? | Confronta x1 con x2 e se necessario effettua lo scambio dei valori\n+-\\\/-+-\\\/-+----+----+------------+\n| m1 | M1 | x3 | x4 |            | m1 \u00e8 un minimo locale, M1 \u00e8 un massimo locale.\n+----+----+----+----+------------+\n\n+----+----+----+----+------------+ \n| x1 | x2 | x3 | x4 | (x1 &gt; x2)? | \n+-\\\/-+-\\\/-+----+----+------------+ \n| m1 | M1 | x3 | x4 | (x3 &gt; x4)? | Confronta x3 con x4\n+----+----+-\\\/-+-\\\/-+------------+\n| m1 | M1 | m2 | M2 |            | m2 \u00e8 un minimo locale, M2 \u00e8 un massimo locale.\n+----+----+----+----+------------+\n\n+----+----+----+----+------------+ \n| x1 | x2 | x3 | x4 | (x1 &gt; x2)? | \n+-\\\/-+-\\\/-+----+----+------------+ \n| m1 | M1 | x3 | x4 | (x3 &gt; x4)? | \n+----+----+-\\\/-+-\\\/-+------------+ \n| m1 | M1 | m2 | M2 | (m1 &gt; m2)? | Confronta m1 e m2, minimi locali\n+-\\\/-+----+-\\\/-+----+------------+\n| r1 | M1 | i1 | M2 |            | In 1\u00b0 posizione il minimo globale, in 3\u00b0 posizione un valore intermedio\n+----+----+----+----+------------+\n\n+----+----+----+----+------------+ \n| x1 | x2 | x3 | x4 | (x1 &gt; x2)? | \n+-\\\/-+-\\\/-+----+----+------------+ \n| m1 | M1 | x3 | x4 | (x3 &gt; x4)? | \n+----+----+-\\\/-+-\\\/-+------------+ \n| m1 | M1 | m2 | M2 | (m1 &gt; m2)? |\n+-\\\/-+----+-\\\/-+----+------------+\n| r1 | M1 | i1 | M2 | (M1 &gt; M2)? | Confronta M1 e M2, massimi locali\n+----+-\\\/-+----+-\\\/-+------------+\n| r1 | i2 | i1 | r4 |            | In 4\u00b0 posizione il massimo globale, in 2\u00b0 posizione un valore intermedio\n+----+----+----+----+------------+\n\n+----+----+----+----+------------+ \n| x1 | x2 | x3 | x4 | (x1 &gt; x2)? | \n+-\\\/-+-\\\/-+----+----+------------+ \n| m1 | M1 | x3 | x4 | (x3 &gt; x4)? | \n+----+----+-\\\/-+-\\\/-+------------+ \n| m1 | M1 | m2 | M2 | (m1 &gt; m2)? |\n+-\\\/-+----+-\\\/-+----+------------+\n| r1 | M1 | i1 | M2 | (M1 &gt; M2)? | \n+----+-\\\/-+----+-\\\/-+------------+\n| r1 | i2 | i1 | r4 | (i2 &gt; i1)? | Confronta i1 e i2, valori intermedi\n+----+-\\\/-+-\\\/-+----+------------+\n| r1 | r2 | r3 | r4 |            |\n+----+----+----+----+------------+\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Codifica<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\nIf x1 &gt; x2 Then\n    Begin\n        temp:=x1  ;\n        x1  :=x2  ;\n        x2  :=temp;\n    End;\nIf x3 &gt; x4 Then \n    Begin \n        temp:=x3  ;\n        x3  :=x4  ;\n        x4  :=temp; \n    End;\nIf x1 &gt; x3 Then\n    Begin\n        temp:=x1  ;\n        x1  :=x3  ;\n        x3  :=temp;\n    End;\nIf x2 &gt; x4 Then\n    Begin\n        temp:=x2  ;\n        x2  :=x4  ;\n        x4  :=temp;\n    End;\nIf x2 &gt; x3 Then\n    Begin\n        temp:=x2  ;\n        x2  :=x3  ;\n        x3  :=temp;\n    End;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Con 6 confronti\/scambi Prova con i numeri La sequenza di confronti (e scambi) segue l&#8217;algoritmo Bubble Sort. Codifica Pascal Con 5 confronti\/scambi Prova con i numeri Ci sono 4 valori da ordinare Codifica<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-20646","post","type-post","status-publish","format-standard","hentry","category-prog"],"_links":{"self":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/20646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/comments?post=20646"}],"version-history":[{"count":33,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/20646\/revisions"}],"predecessor-version":[{"id":32579,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/posts\/20646\/revisions\/32579"}],"wp:attachment":[{"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/media?parent=20646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/categories?post=20646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.valcon.it\/pp\/wp-json\/wp\/v2\/tags?post=20646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}