From 5d329b56b261f2e6883b4353a82558d523565f26 Mon Sep 17 00:00:00 2001 From: Hui Chen Date: Sat, 28 May 2016 00:57:08 -0600 Subject: [PATCH] Added cycle sort --- algorithm/category.json | 3 +- algorithm/sorting/cycle/basic/code.js | 57 +++++++++++++++++++++++++++ algorithm/sorting/cycle/basic/data.js | 4 ++ algorithm/sorting/cycle/desc.json | 13 ++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 algorithm/sorting/cycle/basic/code.js create mode 100644 algorithm/sorting/cycle/basic/data.js create mode 100644 algorithm/sorting/cycle/desc.json diff --git a/algorithm/category.json b/algorithm/category.json index 40bac64f..81c711fa 100644 --- a/algorithm/category.json +++ b/algorithm/category.json @@ -41,7 +41,8 @@ "radix": "Radix Sort", "quick": "Quicksort", "heap" : "Heapsort", - "shell": "Shellsort" + "shell": "Shellsort", + "cycle": "Cycle Sort" } }, "string": { diff --git a/algorithm/sorting/cycle/basic/code.js b/algorithm/sorting/cycle/basic/code.js new file mode 100644 index 00000000..e8fbfc98 --- /dev/null +++ b/algorithm/sorting/cycle/basic/code.js @@ -0,0 +1,57 @@ +logger._print( 'original array = [' + D.join(', ') + ']' ); +var N = D.length; +var writes = 0; +var pos; +var item; +var temp; +for( cycleStart=0; cycleStart<=N-2; cycleStart++ ){ + item = D[cycleStart]; + pos = cycleStart; + for( i=cycleStart+1; i<=N-1; i++ ){ + if( D[i]2), best O(n2), average O(n2)", + "space": "worst O(1) auxiliary" + }, + "References": [ + "Wikipedia" + ], + "files": { + "basic": "Cycle Sort" + } +} \ No newline at end of file