From 30b64897805e9508189e6b34c4f45807e1f80ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Thu, 11 Oct 2012 14:07:41 +0600 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9A=D0=BE=D0=B4=20=D0=BC=D0=BE=D0=B5?= =?UTF-8?q?=D0=B9=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scriptsort.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scriptsort.js diff --git a/scriptsort.js b/scriptsort.js new file mode 100644 index 0000000..b45d90b --- /dev/null +++ b/scriptsort.js @@ -0,0 +1,36 @@ +/*jslint plusplus: true, browser: true, devel: true */ +function sortmass() { + "use strict"; + var n, arr, k, i, r, j, s; + n = prompt('введите длину массива', 1); + arr = []; + if (n > 0) { + //заполняем массив + for (k = 0; k < n; k++) { + arr[k] = parseFloat(prompt('введите число - ' + (k + 1) + '-ый элемент массива')); + if (isNaN(arr[k]) === true) { + alert('не является числом!!!'); + k--; + } + } + /* + метод сортировки включением + */ + for (i = 1; i < arr.length; i++) { + r = arr[i]; + j = i - 1; + while (j >= 0 && arr[j] > r) { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = r; + } + s = ''; + for (k = 0; k < arr.length; k++) { + s = s + ' ' + arr[k]; + } + alert('массив ' + s); + } else { + alert('массив пустой'); + } +} \ No newline at end of file From 763b4216307b6f173a8aa64ce0bf23bbfd0fe922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Mon, 22 Oct 2012 17:58:08 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D0=B0=20=D0=B2=D1=81=D0=B5=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=BB?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scriptsort.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scriptsort.js b/scriptsort.js index b45d90b..81a577e 100644 --- a/scriptsort.js +++ b/scriptsort.js @@ -8,10 +8,10 @@ function sortmass() { //заполняем массив for (k = 0; k < n; k++) { arr[k] = parseFloat(prompt('введите число - ' + (k + 1) + '-ый элемент массива')); - if (isNaN(arr[k]) === true) { + if (isNaN(arr[k]) === true) { alert('не является числом!!!'); - k--; - } + k--; + } } /* метод сортировки включением @@ -19,9 +19,9 @@ function sortmass() { for (i = 1; i < arr.length; i++) { r = arr[i]; j = i - 1; - while (j >= 0 && arr[j] > r) { - arr[j + 1] = arr[j]; - j--; + while (j >= 0 && arr[j] > r) { + arr[j + 1] = arr[j]; + j--; } arr[j + 1] = r; }