Advertisement
Nikivasilew7

quicksort s komentari

Jan 22nd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. // QUICK SORT MAIN
  2.  
  3. import java.text.DecimalFormat;//ИМПОРТИРАМЕ КОНЗОЛАТА ДА ПРИЕМА ЧИСЛА С ПО-ГОЛЯМА ТОЧНОСТ
  4. import java.util.Scanner;//ИМПОРТИРАМЕ КОНЗОЛАТА ЗА СКЕНЕР
  5.  
  6. public class QUICKSORT //СЪЗДАВАМЕ СИ КЛАС
  7. {
  8.  
  9.  
  10. public static void main(String[] args)//СЪЗДАВАМЕ МЕТОД,КОЙТО ДА НЕ ВРЪЩА СТОЙНОСТ
  11. {
  12.  
  13. QUICKSORT myQSort = new QUICKSORT();//ДЕФИНИРАМЕ МАСИВА
  14. DecimalFormat df = new DecimalFormat("#.####");//КАЗВАМЕ ДА ИМА ПО-ГОЛЯМА ТОЧНОСТ
  15.  
  16. Scanner sc = new Scanner(System.in);//ДЕФИНИРАМЕ СКЕНЕР
  17. System.out.print("Input the number of elements : ");//ПРИНТИРАМЕ НА КОНЗОЛАТА КОЛКО ЕЛЕМЕНТА ИСКАМЕ ДА ИМА В МАСИВА,КАТО НЕ СЕ ОТВАРЯ НОВ РЕД В КОНЗОЛАТА
  18.  
  19. int N = sc.nextInt();//СЪЗДАВАМЕ ПРОМЕНЛИВА ЕН,ОТ ТИП ИНТЕДЖЪР
  20.  
  21. int arr1[] = new int[N];//ПЪРВИ МАСИВ С ЕН ЕЛЕМЕНТИ ОТ ТИП ИНТ
  22. int arr2[] = new int[N];//ВТОРИ МАСИВ С ЕН ЕЛЕМЕНТИ ОТ ТИП ИНТ
  23. double arr3[] = new double[N];//ТРЕТИ МАСИВ С ЕН ЕЛЕМЕНТИ ОТ ТИП ДАБЪЛ
  24.  
  25. for (int a = 0; a < N; a++)//ФОР ЦИКЪЛ,С КОЙТО ЗАПЪЛВАМЕ ПЪРВИЯ МАСИВ
  26. {
  27. System.out.printf("Input the [%d] element of arr1: ", a);//ПРИНТИРАМЕ НА КОНЗОЛАТА ДА ИЗПИШЕ ВЪВЕДЕТЕ ЕДИ КОЙ СИ ЕЛЕМЕНТ ОТ МАСИВ 1 И А
  28. arr1[a] = sc.nextInt();//ПЪРВИЯТ МАСИВ Е ОТ ТИП ИНТ
  29. }
  30.  
  31. for (int a = 0; a < N; a++)//ФОР ЦИКЪЛ,С КОЙТО ЗАПЪЛВАМЕ ВТОРИЯ МАСИВ
  32. {
  33. System.out.printf("Input the [%d] element of arr2: ", a);//ПРИНТИРАМЕ НА КОНЗОЛАТА ДА ВЪВЕДЕМ ЕДИ КОЙ СИ ЕЛЕМЕНТ ОТ ВТОРИЯ МАСИВ
  34. arr2[a] = sc.nextInt();//ВТОРИЯ МАСИВ Е ОТ ТИП ИНТ
  35. }
  36.  
  37. System.out.println();//ПРИНТИРАМЕ ЗА ОНАГЛЕДЯВАНЕ
  38.  
  39. for (int k = 0; k < N; k++)//ФОР ЦИКЪЛ,С КОЙТО ЗАПЪЛВАМЕ ТРЕТИЯ МАСИВ
  40. {
  41. double lockal = (double) arr1[k] / arr2[k];//ЛОКЪЛА Е РАВЕН НА ПЪРВИЯ МАСИВ РАЗДЕЛЕН НА ВТОРИЯ МАСИВ
  42. arr3[k] = (lockal);//ТРЕТИЯ МАСИВ Е РАВЕН НА ЛОКЪЛ
  43. }
  44.  
  45. //ПРИНТИРАНЕ ПРЕДИ СОРТИРАНЕТО
  46. for (double i : arr3)//ФОР ЦИКЪЛ,С КОЙТО ПОКАЗВАМЕ,ЧЕ АЙ Е В СЪОТНОШЕНИЕ С ТРЕТИЯ МАСИВ
  47. {
  48. System.out.print(df.format(i));//ПРИНТИРАМЕ АЙ КАТО НЕ ОТВАРЯМЕ НОВ РЕД В КОНЗОЛАТА
  49. System.out.print(" ");//ПРИТИРАМЕ ПРАЗНО МЯСТО
  50. }
  51.  
  52. System.out.println();//ПРИНТИРАНЕ ЗА ОНАГЛЕДЯВАНЕ
  53. System.out.println();//ПРИНТИРАНЕ ЗА ОНАГЛЕДЯВАНЕ
  54.  
  55. QUICKSORT.sort(arr3);//сортираме третия масив
  56.  
  57. // принтиране след сортирането
  58. for (double i : arr3)//фор цикъл,с който казваме,че ай е в съотношение с третия масив
  59. {
  60. System.out.print(df.format(i));//принтираме ай
  61. System.out.print(" ");//принтираме празно място
  62. }
  63.  
  64. System.out.println();//ПРИНТИРАНЕ ЗА ОНАГЛЕДЯВАНЕ
  65. sc.close();//КРАЙ(затваряме)програмата
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement