import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

public class Main {  
public static void main(String[] args) {  
        int n, i;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        int a[] = new int[n];
        for (i = 0; i < n; i++)
        {
            a[i] = s.nextInt();
        }
        quickSort(a, 0, n-1);
        for(i=0;i<10;i++){
          System.out.println(a[i]);
        }
    }
    public static int partition(int a[], int beg, int end){
        int left, right, temp, loc, flag;
        loc = left = beg;
        right = end;
        flag = 0;
        while(flag != 1){
            while((a[loc] <= a[right]) && (loc!=right)){
                right--;
            }
            if(loc==right){
                flag =1;
            }
            else if(a[loc]>a[right]){
                temp = a[loc];
                a[loc] = a[right];
                a[right] = temp;
                loc = right;
            }
            if(flag!=1){
                while((a[loc] >= a[left]) && (loc!=left)){
                    left++;
                }
                if(loc==left){
                    flag =1;
                }
                else if(a[loc] <a[left]){
                    temp = a[loc];
                    a[loc] = a[left];
                    a[left] = temp;
                    loc = left;
                }
            }
        }
        return loc;
    }
    static void quickSort(int a[], int beg, int end){
        int loc;
        if(beg<end){
            loc = partition(a, beg, end);
            quickSort(a, beg, loc-1);
            quickSort(a, loc+1, end);
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: