-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode2.js
More file actions
202 lines (155 loc) · 4.82 KB
/
node2.js
File metadata and controls
202 lines (155 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
let counterValue = 4;
let baseMarginLeft = 5-(counterValue*0.2);
let arr_Value = [];
let arrDivIndexs = [];
let array_container = document.createElement('div');
array_container.className="array_container";
array_container.id="array_container";
document.getElementById("container").appendChild(array_container);
for(let i = 0;i<counterValue;i++)
{
let rndmarr = Math.floor(Math.random() * 100) + 1;
arr_Value.push(rndmarr);
}
function createSpan(n)
{
let baseHeight =20;
let base_width = 70-counterValue;
// if(counterValue>18 && counterValue<24)
// {
// base_width -=10;
// }
// if(counterValue>23 && counterValue<=34)
// {
// base_width -=20;
// baseMarginLeft = 10;
// }
// if(counterValue>34 && counterValue<=60)
// {
// base_width -=30;
// baseMarginLeft = 8;
// }
for(let i = 0;i<n;i++)
{
let div = document.createElement("div");
// div.style.padding = "10px";
div.className="array_div";
div.style.border="1px solid red";
div.style.backgroundColor = "black";
div.style.color="white";
div.style.width=base_width+'px';
div.style.height= (arr_Value[i]*4+baseHeight)+'px';
div.style.marginLeft = baseMarginLeft+'px';
if(n<35){
div.innerHTML="<span>"+arr_Value[i]+"</span>";
}
else
{
div.innerHTML="<span></span>";
}
let array_div = document.getElementById("array_container");
array_div.appendChild(div);
// console.log(arr_Value.indexOf(25));
}
console.log(arr_Value);
}
function counterChange(n)
{
if(n==1 && counterValue<34)
{
counterValue++;
}
else if(n==-1 && counterValue>2){
counterValue--;
}
while (array_container.firstChild) array_container.removeChild(array_container.firstChild);
createSpan(counterValue);
}
createSpan(counterValue);
const myRange = document.getElementById("myRange");
myRange.addEventListener('input', function(){
counterValue = myRange.value;
while (array_container.firstChild) array_container.removeChild(array_container.firstChild);
arr_Value = [];
createSpan(counterValue);
});
arrDivIndexs = document.getElementsByClassName("array_div");
function sorting(params) {
arrDivIndexs = document.getElementsByClassName("array_div");
// console.log(arrDivIndexs);
// arrDivIndexs[0].style.backgroundColor="red";
arr_Value.indexOf(25);
}
function swap(arr_Value, leftIndex, rightIndex){
var temp = arr_Value[leftIndex];
arr_Value[leftIndex] = arr_Value[rightIndex];
arr_Value[rightIndex] = temp;
}
function partition(arr_Value, left, right) {
var pivot = arr_Value[Math.floor((right + left) / 2)], //middle element
i = left, //left pointer
j = right; //right pointer
arrDivIndexs[Math.floor((right + left) / 2)].style.backgroundColor="red";
setTimeout(100);
createSpan(counterValue);
while (i <= j) {
while (arr_Value[i] < pivot) {
i++;
}
while (arr_Value[j] > pivot) {
j--;
}
if (i <= j) {
swap(arr_Value, i, j); //sawpping two elements
i++;
j--;
}
}
return i;
}
function quickSort(arr_Value, left, right) {
var index;
if (arr_Value.length > 1) {
index = partition(arr_Value, left, right); //index returned from partition
if (left < index - 1) { //more elements on the left side of the pivot
quickSort(arr_Value, left, index - 1);
}
if (index < right) { //more elements on the right side of the pivot
quickSort(arr_Value, index, right);
}
}
}
// sorting();
quickSort(arr_Value, 0, arr_Value.length - 1);
console.log(arr_Value);
function animateValue(id, start, end, duration) {
// assumes integer values for start and end
var obj = document.getElementById(id);
var range = end - start;
// no timer shorter than 50ms (not really visible any way)
var minTimer = 50;
// calc step time to show all interediate values
var stepTime = Math.abs(Math.floor(duration / range));
// never go below minTimer
stepTime = Math.max(stepTime, minTimer);
// get current time and calculate desired end time
var startTime = new Date().getTime();
var endTime = startTime + duration;
var timer;
function run() {
var now = new Date().getTime();
var remaining = Math.max((endTime - now) / duration, 0);
var value = Math.round(end - (remaining * range));
obj.innerHTML = value;
if (value == end) {
clearInterval(timer);
}
}
timer = setInterval(run, stepTime);
run();
}
animateValue("value", 100, 25, 5000);
#value {
font-size: 50px;
}
<div id="value">100</div>