怎样删除一维数组中的一个最小数,并且再次确定剩余数中的最小数

用C语言编写,谢谢各位大大的指教,本人急求。请给较详细的程序过程,给出的程序最好能运行。如果满意,本人一定追加分数,不少于悬赏分……

a记录数组元素 N记录个数

#include<stdio.h>

int a[100], N;

int*find_min_element(int*begin, int*end) {
int*ret=begin, *p;
for(p=begin+1; p<end; ++p)
if(*p<*ret) ret=p;
// return the position of the min element in the range [begin,end)
return ret;
}

int*erase_element(int*pos,int*begin,int*end) {
int*p=pos;
for(;p+1<end;++p)
*p=*(p+1);
// return the position of the end of the array
return p;
}

int output(int*begin, int*end) {
int *p=begin;
for(;p<end;++p)
printf("%4d", *p);
printf("\n");
}

int main() {
int i;
// input the array
scanf("%d", &N);
for(i=0;i<N;++i) scanf("%d", a+i);

// work1
// find the position of the min element
int*p = find_min_element(a, a+N);
printf("min element = %d\n", *p);

// erase the element at position p
N=erase_element(p,a,a+N)-a;
//output the new array
printf("elment number : %d\n", N);
output(a,a+N);

// work2
p = find_min_element(a,a+N);
printf("min element = %d\n", *p);

return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答