-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- trim incoming data - add strategy choice - count invocations in quicksort
- Loading branch information
1 parent
887a8e2
commit f8ab643
Showing
2 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
const quickSort = require('./quicksort') | ||
const fs = require('fs') | ||
const data = fs.readFileSync('./QuickSort.txt', 'utf8').split('\r\n').map(num => +num) | ||
quickSort('alwaysFirst')(data) | ||
let result = data.every((val, index) => { | ||
if(index > 0) { | ||
return (val - data[index-1]) >0 | ||
} | ||
return true | ||
}) | ||
|
||
console.log('Result is correct: ', result) | ||
const data = fs.readFileSync('./QuickSort.txt', 'utf8') | ||
.trim() | ||
.split('\r\n') | ||
.map(num => +num) | ||
|
||
let availableStrategies = [ | ||
'alwaysFirst', | ||
'alwaysLast', | ||
'random' | ||
] | ||
// TODO: choose strategy from array "availableStrategies" | ||
let strategy = availableStrategies[0] | ||
let numberOfComparisons = quickSort(strategy)(data) | ||
|
||
console.log(`Number of comparisons for strategy "${strategy}": ${numberOfComparisons}`) | ||
|
||
function checkResult(data) { | ||
return data.every((val, index) => { | ||
if(index > 0) { | ||
return (val - data[index-1]) > 0 | ||
} | ||
return true | ||
}) | ||
} | ||
|
||
console.log('Result is correct: ', checkResult(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters