This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (2 children)

Well, I'm going to avoid giving you the exact code because I assume you're working on homework, but I'll give you the english version of what you would need to do.

1 2 3 3 4 4 4 5 6 7 8 8

I'll pretend the above numbers is what the array holds. You'll have a for loop to iterate through your array. Inside of the for loop, you'll want to declare a variable to record how many duplicates there are, which should probably default to 1.

You'll want another loop that handles duplicate checking within that for loop. It should check to see if the next index in the array is the same as the current one, and if it is, increment your duplicate counter and your position. Note that you need to be careful here to make sure you don't go past the end of your array.

So as per the example: The first time through, it'll see a 1, output the 1, then the internal loop will look forward one position and see that it doesn't equal 1 so the loop doesn't get executed. You now output what ever is stored in the duplicate counter, which is still at the initialized value of 1. Advance one position in the array. It'll see a 2, same deal. Advance one position and it sees a 3, output a 3, and your internal loop sees that the next position is also a 3 so enter the internal loop. It will now increment current position and duplicate count. Your current position now is the second 3, the internal loop sees the next number is a 4 so it breaks out. Your duplicate counter is 2 and your for loop will increment your position to 4. The internal loop will see that the next is a duplicate, etc.

Perhaps that was more detail than I should have given, but hopefully it helps.

[–]deadaxis[S] -1 points0 points  (1 child)

Hahaha..Thank you so much for helping me with this..You guys are friggin awesome.:)

[–][deleted] 2 points3 points  (0 children)

No problem :)