Dutuch flag for 4 colors : I went trough solution for 2 and 3 colors but I am unable to get it for 4 colors.

I am unable to do it for fo four colors.Please help.
Will it be rrbb????yyyggg
how will we swap the green flag.

I tried the solution but it is not working swapping ;last yellow with green


      public class count123 {

	// Java program to sort an array of 0, 1 and 2,3

		static void sort0123(int a[], int arr_size)
		{
			int lo = 0;
			int hi = arr_size - 1;
			int mid = 0,temp=0;
			int h2=arr_size - 1;
			while (mid <= hi)
			{
				switch (a[mid])
				{
				case 0:
				{
					temp = a[lo];
					a[lo] = a[mid];
					a[mid] = temp;
					lo++;
					mid++;
					break;
				}
				case 1:
					mid++;
					break;
				case 2:
				{
					temp = a[mid];
					a[mid] = a[hi];
					a[hi] = temp;
					
					hi--;
					h2=hi;
					break;
				}
				case 3:{
					temp = a[mid];
					a[mid] = a[h2];
					a[h2] = temp;
				//	h2--;
					//hi=h2;
					break;
				
				}
				}
			}
		}

		/* Utility function to print array arr[] */
		static void printArray(int arr[], int arr_size)
		{
			int i;
			for (i = 0; i < arr_size; i++)
				System.out.print(arr[i]+" ");
			    System.out.println("");
		}

		/*Driver function to check for above functions*/
		public static void main (String[] args)
		{
			int arr[] = {0, 1, 0,1,2,2,0,3,3,0,0,1};
			int arr_size = arr.length;
			sort0123(arr, arr_size);
			System.out.println("Array after seggregation ");
			printArray(arr, arr_size);
		}
	}
	/*This code is contributed by Devesh Agrawal*/

