MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / Main

Class Main

Lecture 44 Sorting Problems/src/Main.java:1–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class Main {
2 static void displayArr(int[] num){
3 for(int val : num){
4 System.out.print(val + " ");
5 }
6 System.out.println();
7 }
8 static void sort012_(int[] num){
9 int count_0 = 0, count_1 = 0, count_2 = 0;
10 for (int j : num) {
11 if (j == 0) {
12 count_0++;
13 } else if (j == 1) {
14 count_1++;
15 } else {
16 count_2++;
17 }
18 }
19 int k = 0;
20 while(count_0 > 0){
21 num[k++] = 0;
22 count_0--;
23 }
24 while(count_1 > 0){
25 num[k++] = 1;
26 count_1--;
27 }
28 while(count_2 > 0){
29 num[k++] = 2;
30 count_2--;
31 }
32 }
33 public static void main(String[] args) {
34 int[] num2_ = {2, 2, 1, 2, 2, 0, 1, 0, 2, 0};
35 sort012_(num2_);
36 displayArr(num2_);
37 }
38}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected