您的位置:首页 > 其它

一个数组中存储有且仅有大写和小写字母,编写一个函数对数组内的字母重新排列,让小写字母在所有大写字母之前

2015-07-09 22:50 393 查看
//一个数组中存储有且仅有大写和小写字母,编写一个函数对数组内的字母重新排列,让小写字母在所有大写字母之前
#include<iostream>
using namespace std;
void Partition(char *a,int low,int high)
{
if(a==NULL||low>=high||low<0||high<0)
return;
while(low<high)
{
while(low<high&&isupper(a[high]))
--high;
while(low<high&&islower(a[low]))
++low;
char t=a[high];
a[high]=a[low];
a[low]=t;
}
}

void main()
{
char a[]={'a','A','Z','d','B','s','b','\0'};
Partition(a,0,6);
cout<<a<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: