From the course: Java Profiling

Solution: QuickSort - Java Tutorial

From the course: Java Profiling

Solution: QuickSort

(upbeat music) - [Instructor] For this challenge, you can use your IDE of choice. I'll be using IntelliJ here for our example. Go ahead and input the code that I have here into your IDE. I'm doing a test Java project here. So, go ahead and you can do a, you know, test example to follow along. To start off, what you're already seeing here is that I have already provided an array that we will use for the quick sort. If you want to change these numbers, make it more numbers or less, feel free to do so. So, the 10, seven, eight, nine, one, five. And the goal here is for us to receive an output that puts these numbers in ascending order. So, I already have declared the integer as arr and that is the integer array that we've already inputted. And then, we're going to go ahead and break this down into three steps. And so, I'll do a step one, two and three, starting off with step one. Step one will be the main function. Here we go is our step one, adding it because I'm a slow typer. Here, for step one, what you see is that this is the quick sort algorithm start. We want to select the pivot element using the partition method. We do need to add the partition method into this algorithm here so that it knows what you want to go through and how you want that to happen. And so, I'll showcase you how I've added the pivot and partition method after we've declared the quick sort main function here. So, let's start from the top for step two. So, here the petition has the array, the low declarative aspect, and then the high. You want to index what aspect is the smaller element and then iterate through all the integers in the array. And then, if current element that you're on is smaller than or equal to in pivot. And then, you can swap array inj as you go through and iterate. And then, the alternative right here. So, feel free to try out the method that I'm sharing here. If there is a different method that you would do for the quick sort algorithm, please feel free to share it in the Q&A below. And I'd love to talk more about how you saw the challenge. And then, to get us on the step three, we're simply going to showcase our final answer. What is our final answer? And so, you do that with a print statement. So, go ahead and select the run. And what we have is a sorted array that took less performance and memory, and best case scenario, using the quick sort algorithm. Thank you for following along. And again, feel free to use the example that I have here or do the challenge in your own way and share with me in the Q&A section.

Contents