Deleting element from array

My professor mentioned that she wanted it done so the element is removed from the array and the amount of elements decreases by one, instead of replacing the element with a 0 or NULL. Also I cannot use pointers. I tried looking this up for help but everyone was using std:: and I don't even know what that is yet. This is all I have so far and I know it's not much but I would really appreciate some help.

1
2
3
4
5
6
7
void remove(double arr[], int size)
{
	double delNum;
	cout << "Enter element to be deleted: " << endl;
	cin >> delNum;

}
I cannot use pointers


The function parameter arr is a pointer.
Last edited on
oh okay then I guess I can use pointers. But I still don't know what to do
Last edited on
Pardon the ASCII art, but the idea is that you just shift the parts the array after the element to remove over, overwriting that particular element.
Starting with an array of size 5, like this one, and an instruction to remove element 3:
+---+---+---+---+---+
| 0 | 1 | 2 | 3 | 4 |
+---+---+---+---+---+

Take the fourth element and put it in the third elements place
+---+---+---+---+---+
| 0 | 1 | 2 | 3 | 4 |
+---+---+-^-+-+-+---+
          |   |
          +---+

Then take the fifth element and put it in the fourth element's place
+---+---+---+---+---+
| 0 | 1 | 3 | 3 | 4 |
+---+---+---+-^-+-+-+
              |   |
              +---+

We repeat that "shift" until we have copied the last element over towards the beginning, and that's it. Once we've done that, we may simply ignore the last element, and pretend that the size is one less than it was at the beginning.
+---+---+---+---+
| 0 | 1 | 3 | 4 |
+---+---+---+---+


Note:
std:: is roughly a "surname" for variables.
When it preceeds a name, like it does in std::cout, that's just making sure that we're referring to the right thing named cout.
See: http://www.cplusplus.com/forum/beginner/61121/
Last edited on
Topic archived. No new replies allowed.