Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Random;
- public class Main {
- public static int n = 10;
- public static Random r = new Random();
- public static int [] m = new int [n];
- public static void initArray() {
- for (int i=0; i< n ; i++) {
- m[i] = r.nextInt(100);
- System.out.print(m[i]+ " ");
- }
- System.out.print('\n');
- System.out.println("Массив на вход");
- }
- public static void qsort(int l, int r){
- int key = m[(l+r)/2];
- int i = l;
- int j = r;
- do
- {
- while (m[i]<key) i++;
- while (m[j]>key) j--;
- if (i<=j)
- {
- int b = m[i];
- m[i]=m[j];
- m[j]=b;
- }
- i++;
- j--;
- }
- while (i<=j);
- if (i<r) qsort(i,r);
- if (j>l) qsort(l,j);
- }
- public static void print(){
- for (int i=0; i<n; i++)
- System.out.print(m[i]+" ");
- }
- public static void main(String[] args) {
- initArray();
- qsort(0,n-1);
- print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement