Quick Sort
How do I make an quick sort?
Time complexity: O(n logn)Divide collection into two by determining a pivot point at the middle. Check that the first value in the first collection is smaller than the pivot and the last value in the second collection is larger than the pivot. Do this until the condition is false for both sides. When the condition is false for both sides, swap the values at those indices. Do this until you reach the pivot point. This process is known as partitioning. Recurse the operation above with the array to the left and right until all of the items in the collection are sorted.. What is a quick sort? How do you make a quick sort? This script and codes were developed by Mnicpt on 30 July 2022, Saturday.
Quick Sort - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Quick Sort</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.min.css'>
<link rel='stylesheet prefetch' href='css/obbvpj.css'> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { box-sizing: border-box; font-family: Arial;
}
body { background-color: #ccc;
}
.console { position: relative; display: flex; justify-content: space-between; width: 80%; margin: 40px auto;
}
.item { background-color: white; width: 8%; height: 50px; border: 1px solid #aaa; text-align: center; line-height: 50px; transition: all 1s ease-out;
}
.jasmine_html-reporter { display: none;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="console"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.min.js'></script>
<script src='js/obbvpj.js'></script>
<script src='js/qbqepw.js'></script> <script src="js/index.js"></script>
</body>
</html>
Quick Sort - Script Codes CSS Codes
* { box-sizing: border-box; font-family: Arial;
}
body { background-color: #ccc;
}
.console { position: relative; display: flex; justify-content: space-between; width: 80%; margin: 40px auto;
}
.item { background-color: white; width: 8%; height: 50px; border: 1px solid #aaa; text-align: center; line-height: 50px; transition: all 1s ease-out;
}
.jasmine_html-reporter { display: none;
}
Quick Sort - Script Codes JS Codes
var nextSwap = 1;
var app = (function() { return { items: [], drawItems: function(items) { app.items = items; var html = ""; for (var i = 0; i < items.length; i++) { var id = i; html += "<div class=\"item\" data-item=\"" + app.items[i] + "\">" + app.items[i] + "</div>"; } $(".console").html(html); } }
}());
var quickSort = function() { function swap(items, firstIndex, secondIndex) { // swap array elements var temp = items[firstIndex]; items[firstIndex] = items[secondIndex]; items[secondIndex] = temp; var firstItem = 0, secondItem = 0; if (firstIndex < secondIndex) { firstItem = items[firstIndex]; secondItem = items[secondIndex]; } else { firstItem = items[secondIndex]; secondItem = items[firstIndex]; } // swap DOM elements setTimeout(function() { var transform = new Transform(); var elem1 = $(".item[data-item=" + firstItem + "]")[0], elem2 = $(".item[data-item=" + secondItem + "]")[0], position1 = elem1.transformLeft == undefined ? elem1.offsetLeft : elem1.transformLeft, position2 = elem2.transformLeft == undefined ? elem2.offsetLeft : elem2.transformLeft, diff = parseInt(Math.abs(position2 - position1), 10); if (position1 != position2) { if (position2 > position1) { transform.translateX(elem1, diff); transform.translateX(elem2, -diff); //alert("2>1--Swapping " + firstItem + " and " + secondItem + ": at " + position1 + "px and " + position2 + "px at a difference of " + diff + "px."); } else { transform.translateX(elem1, -diff); transform.translateX(elem2, diff); //alert("1>2--Swapping " + firstItem + " and " + secondItem + ": at " + position1 + "px and " + position2 + "px at a difference of " + diff + "px."); } } }, 1000 * nextSwap++); } function partition(items, left, right) { var pivot = items[Math.floor((right + left) / 2)], i = left, j = right; while (i <= j) { while (items[i] < pivot) { i++; } while (items[j] > pivot) { j--; } if (i <= j) { swap(items, i, j); i++; j--; } } return i; } function quickSort(items, left, right) { var index; if (items.length > 1) { index = partition(items, left, right); if (left < index - 1) { quickSort(items, left, index - 1); } if (index < right) { quickSort(items, index, right); } } return items; } return quickSort;
}();
// first call
var items = [4, 2, 6, 5, 3, 9, 10, 1, 25, 18];
app.drawItems(items);
setTimeout(function() { var result = quickSort(items, 0, items.length - 1);
}, 1000);
Developer | Mnicpt |
Username | mnicpt |
Uploaded | July 30, 2022 |
Rating | 3 |
Size | 7,584 Kb |
Views | 48,576 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Fading Divider | 1,728 Kb |
3,268 Kb | |
Rotate Image | 1,843 Kb |
Contact Snippet | 1,815 Kb |
Graph API | 4,456 Kb |
Solve Intersecting Lines | 1,792 Kb |
IOS 7 Layering | 2,931 Kb |
JavaScript OO | 1,904 Kb |
Apple Playing Cards | 4,618 Kb |
Sketchy Box | 3,033 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Mobile Nav Menu | AliKlein | 4,745 Kb |
Working around OS X Dynamic Scrollbars | Jrjenk | 2,279 Kb |
Vertically rotating text with CSS | Nopr | 2,141 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Drag n Drop | Martin42 | 2,594 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Twitch | SarahDunlap | 2,937 Kb |
Jochaho Skeleton | Dhanushbadge | 1,689 Kb |
Twitch.tv API | Ryzokuken | 2,618 Kb |
Incremental game | Eprouver | 5,868 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!