int search(int a[]) {
int i,V,index;
printf("Enter the element (V),That you want to find:>");
scanf("%d",&V);
for (i=0;i<N;i++) {
if(a[i]==V) {
V=a[i];
index=i;
}
}
printf("%d is located in a[%d].",V,index
)
最佳答案
如果您不关心元素的顺序,您可以在 O(1) 时间内删除找到的元素。
// Find the element you're looking for.
int index = find(A, V);
// Stuff the last element into the index found.
A[index] = A[N-1];
// Reduce the total number of elements.
N--;
关于c - 如何删除数组中找到的元素并将数组元素向左移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4491625/