package labodeva;
import java.util.Scanner;
public class odev5dene {
static int[] quick(int kucuk,int buyuk,int[] arr,int pivot) {
int bos[] = new int[100];
int t=0;
while(kucuk<=buyuk) { // buyuk is big kucuk is small
if(arr[kucuk]<=arr[pivot]) {
kucuk++;
}
else if(arr[buyuk]>arr[pivot]) {
buyuk--;
}
else{
bos[0] = arr[kucuk];
arr[kucuk]=arr[buyuk];
arr[buyuk] = bos[0];
buyuk--;
kucuk++;
}
}
if(kucuk>buyuk) {
bos[0] = arr[pivot];
arr[pivot]=arr[buyuk];
arr[buyuk]=bos[0];
pivot=buyuk; //sil
}
if(pivot-1>0&&pivot+1<arr.length) {
quick(0,pivot-1,arr,0);
quick(pivot+1,arr.length-1,arr,pivot+1);
}
if(pivot+1<arr.length&&pivot-1<0) {
quick(pivot+1,arr.length-1,arr,pivot+1);
}
return arr;
}
public static void main(String[] args) {
int a =0;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter how many value do you want to add the array : ");
a=scan.nextInt();
int k[] =new int[a];
for(int i=0;i<a;i++) {
System.out.println("Please enter your "+(i+1)+".value");
k[i]=scan.nextInt();
}
k=quick(0,a-1,k,0); // it starts 0. element as pivot and goes on and also small and equal number value starts here big number value starts at the end of list
for(int i=0;i<a;i++) {
System.out.println(k[i]);
}
}
}
i wrote this code and it sorts the given array but i tried to do quicksort is this quicksort i am not sure can you check ?