Hi ! I need help here .
I have to write a function that delete a value of one element in the array , and shift the elemnts that follows it , for example :
the values in the array are : 54 25 99 10
and if i want to delete the value 25 it has to become : 54 99 10
also i have to include a counter to count the values that i deleted it
so i did this function , but sth is missing and idk what !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void deleteByValue(int a[], int &size)
{
int value, count=0;
cout <<"Eneter value of element to be deleted: ";
cin >> value;
for( int i=0; i<=size-1; i++ )
if (value == a[i])
{
count++;
a[i]=a[i+1];
size--;
}
cout << count << " numbers were deleted. " << endl << "Done!!" <<endl;
}
void deleteByValue(int a[], int &size)
{
int value, count=0;
cout <<"Eneter value of element to be deleted: ";
cin >> value;
for( int i=0; i<=size-1; i++ )
if (value == a[i])
{
count++;
for (int j=i;j<size-1;j++)
a[j]=a[j+1];
size--;
i--;
}
cout << count << " numbers were deleted. " << endl << "Done!!" <<endl;
}
You may want to check an insure that your code will remove a duplicate that is next to each other in the array. Try your code with "54 25 25 99" as your array.