C语言指针求最大值问题题目要求找出数列中最大值,挑出来,放到句首,其他数按原来顺序排列Code:/* The function maxToFront should take an array as input and* move the maximum element to the front,keeping all other* eleme
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/04 01:08:01
C语言指针求最大值问题题目要求找出数列中最大值,挑出来,放到句首,其他数按原来顺序排列Code:/* The function maxToFront should take an array as input and* move the maximum element to the front,keeping all other* eleme
C语言指针求最大值问题
题目要求找出数列中最大值,挑出来,放到句首,其他数按原来顺序排列
Code:/* The function maxToFront should take an array as input and
* move the maximum element to the front,keeping all other
* elements in their initial order.*/
#include
#include
void maxToFront(int *a,int n) {
/* BEGIN ANSWER -- do not delete this line */
int temp=0;
int i=0;
while(i*(a+n-i-1)){
temp=*(a+n-i);
*(a+n-i)=*(a+n-1-i);
*(a+n-i-1)=temp;
i++;
}
else{i++;}
}
/* END ANSWER -- do not delete this line */
}
/* PLEASE DO NOT EDIT THE 'main' FUNCTION.IT IS THERE
* FOR TESTING PURPOSES.*/
int main (void) {
int i;
int b[10]={6,2,4,44,5,-10,-6,5,8,2};
int c[15]={2,3,44,-6,4,8,-2,44,9,6,1,3,4,-11,0};
maxToFront(b,10);
printf("After maxToFront,b is %d",b[0]);
for(i=1; i
C语言指针求最大值问题题目要求找出数列中最大值,挑出来,放到句首,其他数按原来顺序排列Code:/* The function maxToFront should take an array as input and* move the maximum element to the front,keeping all other* eleme
你看maxToFront函数能不能这样写:用一个变量来存整数组的最大值,一个存最大值的下标,遍历玩整个数组之后从最大值的下标开始,前面的所有的数都向后移动一个位置,最后再把最大值赋给数组的第一个元素,
void maxToFront(int *a,int n) {
/* BEGIN ANSWER -- do not delete this line */
int i=1;
int max;
int x=0;
max=*a;
while(i