Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf745921

Browse files
committed
Merge branch 'master' ofhttps://github.com/thinker3197/AlgorithmVisualizer into thinker3197-master
2 parentse54ab7c +4d50aae commitf745921

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

‎algorithm/category.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"selection":"Selection Sort",
2020
"bubble":"Bubble Sort",
2121
"quick":"Quicksort",
22-
"merge":"Mergesort"
22+
"merge":"Mergesort",
23+
"heap" :"Heap Sort"
2324
}
2425
},
2526
"etc": {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
tracer._print('Original array = ['+D.join(', ')+']');
2+
3+
functionheapSort(array,size){
4+
vari,j,temp;
5+
6+
for(i=Math.ceil(size/2)-1;i>=0;i--){
7+
heapify(array,size,i);
8+
}
9+
10+
for(j=size-1;j>=0;j--){
11+
temp=array[0];
12+
array[0]=array[j];
13+
array[j]=temp;
14+
15+
tracer._select(j);
16+
17+
heapify(array,j,0);
18+
tracer._print('Swapping elemnts : '+array[0]+' & '+array[j]);
19+
20+
tracer._deselect(j);
21+
}
22+
}
23+
24+
functionheapify(array,size,root){
25+
26+
varlargest=root;
27+
varleft=2*root+1;
28+
varright=2*root+2;
29+
vartemp;
30+
31+
if(left<size&&array[left]>array[largest]){
32+
largest=left;
33+
}
34+
35+
if(right<size&&array[right]>array[largest]){
36+
largest=right;
37+
}
38+
39+
if(largest!=root){
40+
temp=array[root];
41+
array[root]=array[largest];
42+
array[largest]=temp;
43+
44+
tracer._notify(largest,root);
45+
46+
tracer._print('Swapping elemnts : '+array[root]+' & '+array[largest]);
47+
48+
heapify(array,size,largest);
49+
}
50+
}
51+
52+
tracer._sleep(1000);
53+
tracer._pace(800);
54+
55+
heapSort(D,10);
56+
57+
tracer._print('Final array = ['+D.join(', ')+']');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vartracer=newArray1DTracer();
2+
varD=Array1D.random(10);
3+
tracer._setData(D);

‎algorithm/sorting/heap/desc.json‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Heap Sort":"Heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum.",
3+
"Complexity": {
4+
"time":"worst O(n log n), best O(n log n), average O(n log n)",
5+
"space":"worst O(1) auxiliary"
6+
},
7+
"References": [
8+
"<a href='https://en.wikipedia.org/wiki/Heapsort'>Wikipedia</a>"
9+
],
10+
"files": {
11+
"basic":"Basic"
12+
}
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp