FANDOM


//
$(document).ready(function () {
	function insertDemoHTML($container, demoName, textStorage, sortingFunctions, descriptions) {
		// form html initialization
		var html = '<label>Array size:</label><select id="demo-' + demoName + '-arraysize" style="margin-left:10px"><option>100</option><option>500</option><option>1000</option><option>5000</option><option>10000</option><option selected="selected">50000</option><option>100000</option><option>250000</option><option>500000</option><option>1000000</option></select><label style="margin-left:10px">Data type:</label><select id="demo-' + demoName + '-datatype" style="margin-left:10px"><option>Integer</option><option>String</option></select><button id="demo-' + demoName + '-test" style="margin-left:10px">Run Test</button><button id="demo-' + demoName+ '-reset" style="margin-left:10px">Reset</button><textarea id="demo-' + demoName + '-textarea" style="margin-top:10px; font-family:monospace; width:99%; height:300px; overflow:scroll;"></textarea>';
		$container.text('');
		$container.append(html);
 
		// textarea initialization
		textStorage.defaultText = 'Array size     Data type';
		var dashes = '';
		for (var i = 0; i < descriptions.length; i++) {
			textStorage.defaultText += '     ' + descriptions[i];
		}
		for (i = 0; i < textStorage.defaultText.length; i++) {
			dashes += '-';
		}
		textStorage.defaultText += '\n' + dashes + '\n';
		$(('#demo-' + demoName + '-textarea')).val(textStorage.defaultText);
 
		// gets item in field of given length, aligned right or left
		function format(item, fieldLength, alignRight) {
			var i, len, s = '';
			item += '';
			for (i = 0, len = fieldLength - item.length; i < len; i++) {
				s += ' ';
			}
			if (alignRight) {
				item = s + item;
			} else {
				item += s;
			}
			return item;
		}
 
		// test button event handler
		textStorage.testText = '';
		$(('#demo-' + demoName + '-test')).click(function () {
			var size = parseInt($(('#demo-' + demoName + '-arraysize')).val());
			var type = $(('#demo-' + demoName + '-datatype')).val();
			var a = [];
			a[0] = SortingDemo.randomArray(size, size * 10, (type === 'String'));
			for (var i = 1; i < sortingFunctions.length; i++) {
				a[i] = a[0].slice(); // copy the array
			}
			var time = [];
			for (i = 0; i < sortingFunctions.length; i++) {
				time[i] = sortingFunctions[i](a[i]);
			}
			var text = format(size, 10, true) + '     ' + format(type, 9, true);
			for (i = 0; i < time.length; i++) {
				text += '     ' + format(time[i], descriptions[i].length, true);
			}
			text += '\n';
			textStorage.testText = text + textStorage.testText;
			$(('#demo-' + demoName + '-textarea')).val(textStorage.defaultText + textStorage.testText);
		});
	}
 
	// Speed demo
	function speedDemo() {
		var $speed = $('#demo-speed-container');
		insertDemoHTML($speed, 'speed', {}, [SortingDemo.nativeSort, SortingDemo.mergeSort, SortingDemo.quickSort], ['NativeSort', 'MergeSort', 'QuickSort']);
		$('#demo-speed-reset').click(function () {
			speedDemo();
		});
	}
 
	// Quicksort Variants
	function quicksortDemo() {
		var $quicksort = $('#demo-quicksort-variants-container');
		insertDemoHTML($quicksort, 'quicksort', {}, [SortingDemo.quickSortRecursive, SortingDemo.quickSortStack1, SortingDemo.quickSortStack2, SortingDemo.quickSortStack3, SortingDemo.quickSortStack4, SortingDemo.quickSort], ['QS Recursive', 'QS Stack 1', 'QS Stack 2', 'QS Stack 3', 'QS Stack 4', 'QuickSort']);
		$('#demo-quicksort-reset').click(function () {
			quicksortDemo();
		});
	}
 
	// Mergesort Variants
	function mergesortDemo() {
		var $mergesort = $('#demo-mergesort-variants-container');
		insertDemoHTML($mergesort, 'mergesort', {}, [SortingDemo.mergeSortStack, SortingDemo.mergeSortRecursive, SortingDemo.mergeSort], ['MS Stack', 'MS Recursive', 'MergeSort']);
		$('#demo-mergesort-reset').click(function () {
			mergesortDemo();
		});
	}
 
	// delete siderail
	$('#WikiaRail').remove();
	$('#WikiaMainContent').css('width', '1010px');
 
	// setup demos
	speedDemo();
	quicksortDemo();
	mergesortDemo();
});
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.