FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptExercises/quickSort.js at master · marshmeryl/JavaScriptExercises · GitHub
marshmeryl
/
JavaScriptExercises
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptExercises
/
quickSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (55 loc) · 1.46 KB
Breadcrumbs
JavaScriptExercises
/
quickSort.js
Copy path
File metadata and controls
63 lines (55 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
function
quickSort
(
array
)
{
result
=
array
.
slice
(
)
;
_sortSegment
(
result
,
0
,
result
.
length
)
;
return
result
;
}
function
_sortSegment
(
array
,
start
,
length
)
{
if
(
length
<
2
)
{
return
;
}
var
pivotIndex
=
start
+
length
-
1
;
var
pivotValue
=
array
[
pivotIndex
]
;
for
(
var
i
=
start
;
i
<
pivotIndex
;
i
++
)
{
while
(
array
[
i
]
>
pivotValue
)
{
_swap
(
array
,
i
,
pivotIndex
-
1
)
;
_swap
(
array
,
pivotIndex
-
1
,
pivotIndex
)
;
pivotIndex
--
}
}
_sortSplitSegment
(
array
,
start
,
length
,
pivotIndex
)
;
}
function
_sortSplitSegment
(
array
,
start
,
length
,
pivotIndex
)
{
_sortSegment
(
array
,
start
,
pivotIndex
-
start
)
;
_sortSegment
(
array
,
pivotIndex
+
1
,
array
.
length
-
pivotIndex
-
1
)
;
}
function
_swap
(
array
,
indexOne
,
indexTwo
)
{
var
temp
=
array
[
indexOne
]
;
array
[
indexOne
]
=
array
[
indexTwo
]
;
array
[
indexTwo
]
=
temp
;
}
var
testCase
=
[
[
]
,
[
1
]
,
[
1
,
2
]
,
[
-
2
,
1
]
,
[
2
,
1
,
3
]
,
[
3
,
1
,
2
]
,
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
]
,
[
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
]
,
[
11
,
12
,
13
,
14
,
5
,
6
,
7
,
8
,
9
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
0
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
1
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
2
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
3
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
4
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
5
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
6
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
7
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
8
]
,
[
3
,
7
,
8
,
5
,
2
,
1
,
9
,
5
,
9
]
]
;
for
(
var
i
=
0
;
i
<
testCase
.
length
;
i
++
)
{
console
.
log
(
"=================================="
)
;
console
.
log
(
testCase
[
i
]
.
join
(
", "
)
)
;
console
.
log
(
quickSort
(
testCase
[
i
]
)
.
join
(
", "
)
)
;
}
Back
|
FazBrowse Home
|
New Git URL