### Remove Duplicates from Array

Here is the algorithm we need to write code for

Algorithm for delete_duplicates() function
For each character in the array
For each character beyond the one the outer loop is on
if the character ffrom the inner loop matches the one from the outer loop
For all characters beyond the current one
copy the character to the prior array element
decrement size

here is what we have so far. We are a bit lost, help would be nice. Thanks in advance.

 ``123456789`` `````` int dele(char array[], int size) { for (int i=0; i
The second loop doesn't quite match the description in the algorithm.

How would you like us to help? Are you having difficulty understanding the prompt or implementing the algorithm?

-Albatross
I understand what the prompt is asking for, but not entirely sure on how to write the code for it. I tried googling some ways how how to do it but they all looked messy and very confusing. Looking for some help in what direction to go and how to write it.
Still looking for some answers. Thanks
Still very lost, tried many things but have yet to get anything to work.
Take a "banana".

We look at 'b' and then check "anana", but find nothing.

We look at 'a' and then check "nana". We find 'a', so "ana" shrinks to "na". We find 'a' again, so "a" shrinks to "".

The word is now "bann", and we look at 'n', find another 'n', which disappears.

The word is "ban" and we are done.

What we look at is the outer loop. What we check is the second loop. What we shrink is the "move and decrease size".

You have tried many things. They must be more than the code in the initial post. Please show. Can you say how or why the "best" attempt fails? Try to speculate.
Well, it seems like you have lines 1-4 of the description down alright (except the second loop that I pointed out to you). So here are a few hints.

Algorithm Line 5: Notice how every previous line involving the word "for each" has a for loop in it. I assume "current one" refers to the element that the outermost loop is on.

Algorithm Line 6: lower indexed-element = greater indexed-element.

Algorithm Line 7: Reduce size by 1. You can take care of freeing unused memory later.

-Albatross
Not sure I understand what line 2 in the algorithm is asking for, could you possibly reword it so I understand it? And thanks a lot for the help, starting to get a grasp on this thing with your help!!
 For each character with an index greater than i

-Albatross
That helps a lot, thank you!
Topic archived. No new replies allowed.