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.
1 2 3 4 5 6 7 8 9
int dele(char array[], int size)
{
for (int i=0; i<size; i++)
{
for(int j=1; j<size; j++)
{
if(array[i] == array[j])
{
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.
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.
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!!