Skip to content

Commit fa272c7

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5bf5bc3 + 0a12579 commit fa272c7

File tree

10 files changed

+305
-219
lines changed

10 files changed

+305
-219
lines changed

PortJob/MergeSort/css/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ ul.insElements li.pivot div {
4343
background-color: #f1f500;
4444
}
4545

46+
ul.insElements li.highlightNode div {
47+
background-color: #f4a742;
48+
}
49+
ul.insElements li.pivot div {
50+
background-color: #f1f500;
51+
}
52+
4653
ul.insElements li.highlightNode div {
4754
background-color: #f4a742;
4855
}

PortJob/MergeSort/js/.idea/workspace.xml

Lines changed: 58 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PortJob/MergeSort/js/MergeSortAlgorithm.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,63 +43,71 @@ function mergesort(array) {
4343
}
4444
}
4545
function merge(left, right) {
46-
console.log("--------------------------------------------------");
47-
console.log("--------------------------------------------------");
48-
console.log("--------------------------------------------------");
46+
console.log("array " + copyArray + " left " + left + "right " + right);
4947
var result = [];
5048
var tempLeftIndex = 0;
5149
var tempRightIndex = 0;
5250
var start = copyArray.indexOf(left[0]);
5351
var end = copyArray.indexOf(right[right.length - 1]);
5452
var counter = start;
55-
var testing = copyArray;
53+
var testing = copyArray.slice(0);
5654
while (tempLeftIndex < left.length && tempRightIndex < right.length) {
5755
//Compare the elements from each array
58-
//highLightNode(tempLeftIndex)
59-
//highLightNode(tempRightIndex)
56+
//viewer.highLightNode(tempLeftIndex)
57+
//viewer.highLightNode(tempRightIndex)
6058
if (left[tempLeftIndex] < right[tempRightIndex]) {
61-
result.push(left[tempLeftIndex]);
6259
viewer.liftElements(copyArray.indexOf(left[tempLeftIndex]), copyArray.indexOf(left[tempLeftIndex]));
63-
//moveElement(tempLeftIndex, counter)
64-
//pushElements(counter, end, !left) to the right
65-
console.log("tempLeftIndex " + tempLeftIndex + " number: " + left[tempLeftIndex]);
60+
console.log("left " + left + " index " + tempLeftIndex + " value " + left[tempLeftIndex]);
61+
console.log(copyArray);
62+
console.log("index of : " + copyArray.indexOf(left[tempLeftIndex]) + " end " + end + " to place " + counter);
63+
viewer.moveElementToPlace(copyArray.indexOf(left[tempLeftIndex]), end, counter);
64+
//viewer.pushElements(counter, end, !left) to the right
65+
result.push(left[tempLeftIndex]);
6666
testing[counter] = left[tempLeftIndex];
6767
counter++;
6868
tempLeftIndex++;
6969
}
7070
else {
71-
//moveElement(tempRightIndex, counter)
72-
//pushElements(counter, end, !left) to the right
73-
result.push(right[tempRightIndex]);
71+
console.log(right[tempRightIndex]);
72+
console.log("index of : " + copyArray.indexOf(right[tempRightIndex]) + " end " + end + " to place " + counter);
7473
viewer.liftElements(copyArray.indexOf(right[tempRightIndex]), copyArray.indexOf(right[tempRightIndex]));
74+
viewer.moveElementToPlace(copyArray.indexOf(right[tempRightIndex]), end, counter);
75+
//viewer.pushElements(counter, end, !left) to the right
76+
result.push(right[tempRightIndex]);
7577
testing[counter] = right[tempRightIndex];
7678
counter++;
7779
tempRightIndex++;
7880
}
7981
}
8082
if (right.slice(tempRightIndex).length > 0) {
8183
var moreRight = right.slice(tempRightIndex);
82-
console.log("more right : " + moreRight);
8384
for (var i = 0; i < moreRight.length; i++) {
8485
viewer.liftElements(copyArray.indexOf(right.slice(tempRightIndex)[i]), copyArray.indexOf(right.slice(tempRightIndex)[i]));
8586
viewer.deselectPivotElement(copyArray.indexOf(right.slice(tempRightIndex)[i]));
87+
viewer.moveElementToPlace(copyArray.indexOf(right[tempRightIndex]), end, counter);
88+
//viewer.pushElements(counter, end, !left) to the right????
89+
console.log("index of : " + copyArray.indexOf(right[tempRightIndex]) + " end " + end + " to place " + counter);
8690
testing[counter] = moreRight[i];
8791
counter++;
88-
//moveElement()
8992
}
9093
}
9194
if (left.slice(tempLeftIndex).length > 0) {
9295
var moreLeft = left.slice(tempLeftIndex);
93-
console.log("more left : " + moreLeft);
9496
for (var i = 0; i < moreLeft.length; i++) {
9597
viewer.liftElements(copyArray.indexOf(left.slice(tempLeftIndex)[i]), copyArray.indexOf(left.slice(tempLeftIndex)[i]));
9698
viewer.deselectPivotElement(copyArray.indexOf(left.slice(tempLeftIndex)[i]));
99+
viewer.moveElementToPlace(copyArray.indexOf(left[tempLeftIndex]), end, counter);
100+
//viewer.pushElements(counter, end, !left) to the right???
101+
console.log("index of : " + copyArray.indexOf(left[tempLeftIndex]) + " end " + end + " to place " + counter);
97102
testing[counter] = moreLeft[i];
98103
counter++;
99104
}
100105
}
101-
console.log("ArrEnd: " + testing);
102-
copyArray = testing;
106+
console.log("------------------------");
107+
console.log(copyArray);
108+
console.log(testing);
109+
console.log("------------------------");
110+
copyArray = testing.slice(0);
103111
return result.concat(left.slice(tempLeftIndex)).concat(right.slice(tempRightIndex));
104112
}
105113
function delay() {

0 commit comments

Comments
 (0)