天天看點

java實作将數組的大小寫字母分開

 可以利用快排的一次排序思想  要時刻記得快排的思想

//判斷是不是大寫
	public static boolean isUpper(char c) {
		if (c >= 'A' && c <= 'Z') {
			return true;
		} else {
			return false;
		}
	}

	//判斷是不是小寫
	public static boolean isLower(char c) {
		if (c >= 'a' && c <= 'z') {
			return true;

		} else {
			return false;
		}
	}

	//将數組裡的大小寫字母分開
	public static void partitionChar(char A[], int low, int higt) {
		while (low < higt) {
			while (low < higt && isUpper(A[higt]))
				--higt;
			while (low < higt && isLower(A[low]))
				++low;
			char temp;
			temp = A[higt];
			A[higt] = A[low];
			A[low] = temp;
		}
	}
	public static void main(String[] args) {
		char a[]={'a','A','B','d','B','s','b'};
		
		partitionChar(a,0,6);
		System.out.print(a);
	}
           

繼續閱讀