From 6d6948c0787b66f2a856d064dfdd8796154ae348 Mon Sep 17 00:00:00 2001 From: Sergey Zhigalov Date: Wed, 31 Oct 2012 16:53:54 +0600 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=83=D0=B7=D1=8B=D1=80=D1=8C=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RangeArray.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 15 +++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 RangeArray.js create mode 100644 index.html diff --git a/RangeArray.js b/RangeArray.js new file mode 100644 index 0000000..e4e75ac --- /dev/null +++ b/RangeArray.js @@ -0,0 +1,58 @@ +var array = []; +var maxIntValue = 20; +var arrayLength = 7; + +function getRandomInt() { + 'use strict'; + return Math.floor(Math.random() * maxIntValue); +} + +function arrayToString() { + 'use strict'; + var i, arrayString = ""; + for (i = 0; i < arrayLength; i = i + 1) { + arrayString += array[i] + "\t"; + } + return arrayString; +} + +function CreateArray() { + 'use strict'; + var i; + for (i = 0; i < arrayLength; i = i + 1) { + array[i] = getRandomInt(); + } + document.getElementById("OriginalArray").innerHTML = arrayToString(); +} + +function addStep() { + 'use strict'; + var step = document.createElement('li'); + step.innerHTML = arrayToString(); + document.getElementById('RangeSteps').appendChild(step); +} + +function clearSteps() { + 'use strict'; + var element = document.getElementById('RangeSteps'); + while (element.childNodes[0]) { + element.removeChild(element.childNodes[0]); + } +} + +function RangeArray() { + 'use strict'; + clearSteps(); + var i, j, value; + for (i = 0; i < arrayLength - 1; i = i + 1) { + for (j = 0; j < arrayLength - i - 1; j = j + 1) { + if (array[j] > array[j + 1]) { + value = array[j]; + array[j] = array[j + 1]; + array[j + 1] = value; + + addStep(); + } + } + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..9868fca --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + Сортировка массива + + + +

Алгоритм: сортировка пузырьком

+

Выполнил: Жигалов Сергей, МГКН - 2, УрФУ, 2012

+ + +
+ + + \ No newline at end of file