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