关于动态分组数组的问题
数组排序
编写一个函数void sort(int *a,int n),在主函数中调用该函数对该数组排序。
请帮忙编写一下这个程序,要求使用动态分配数组。
[解决办法]
- C/C++ code
void sort(int *a,int n){ int i,j,flag,temp; for(i = 0; i < n-1; i++) { flag = 1; for(j = 0; j < n-i-1; j++) { if(a[j] > a[j+1]) { temp= a[j]; a[j] = a[j+1]; a[j+1] = temp; flag = 0; } } if(1 == flag) { break; } } }
[解决办法]
楼主啊,你这是在字符串数组中查找指定的字符是吧,我随便改一下,
#include <iostream>
using namespace std;
void find(char *s,char t);
void main ()
{
char *s="the";
char t='t';
find(s, t);
}
void find (char *s,char t)
{
char *a =new char[];
a=s;
int i=0;
while(a[i]=='t')
{
cout<<i<<endl;
i++;
}
}