Datasets:

ArXiv:
License:
File size: 712 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

public class Dutch_National_Flag {
	
	public static void DNF(String A[]) {
		int n=A.length;
		int low=0,high=n-1,mid=0;
		String temp;
		while(mid<=high) {
			switch(A[mid]) {
			case "RED":
				temp=A[low]; A[low]=A[mid]; A[mid]=temp;
				low++;mid++;
				break;
			case "BLUE":
				mid++;
				break;
			case "GREEN":
				temp=A[mid]; A[mid]=A[high]; A[high]=temp;
				high--;
				break;
			}
		}
	}
	public static void Display(String A[]) {
		for(int i=0;i<A.length;i++) {
			System.out.print(A[i]+" ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		String A[]= {"RED","BLUE","BLUE","RED","GREEN","GREEN","RED","RED","BLUE","GREEN"};
		Display(A);
		DNF(A);
		Display(A);
	}

}