//题目:将数组中的大写字母与小写字母分开(利用快速排序)
#include<iostream>
using namespace std;
bool isUpper(char a)
{
if(a>='A' && a<='Z')
return true;
else
return false;
}
bool isLower(char a)
{
if(a>='a' && a<='z')
return true;
else
return false;
}
void Partition(char a[],int low,int high)//快速排序
{
while(low<high)
{
while(low<high && isUpper(a[high])) --high;
while(low<high && isLower(a[low])) ++low;
char temp = a[high];
a[high] = a[low];
a[low] = temp;
}
}
void main()
{
char A[5] = {'a','B','C','d','n'};
Partition(A, 0, 4);
for(int i = 0;i<5;++i)
cout<<A[i]<<' ';
cout<<endl;
}
将数组中的大写字母与小写字母分开
最新推荐文章于 2020-06-01 14:37:21 发布