Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an array in which i have stored multiple date values
Now the issue is i have to find the duplicate dates in the same array
Conditions :

1) all the values should be in the same array.
2) each value in the array should be compared with every other value in the array.

Thanks.
Posted
Comments
CHill60 7-Feb-13 6:21am    
Have a go at this yourself first then post a question with your code if you hit a problem
Matthew Faithfull 7-Feb-13 6:22am    
That sounds like homework which means if I answer it I get your credit, your future job and all your money, so I'd better not. I'll give you this clue. Sorting the array into order first makes the job a lot easier.
Keith Barrow 7-Feb-13 6:27am    
What have you tried? Please post the code and/or explain what you are having problems with.
Captain Price 7-Feb-13 6:35am    
Try googling "LOOKUP TABLES", you'll find !

A simplistic solution would be to loop through the array twice. The first loop would go from the first element to the second off last element (the reason why will become clear in a moment). The second loop will go from the second element to the last one, and will be contained in the first loop.

Basically, you will use the value in the outer loop as a comparison for every item in the inner loop. This is why the loops have the start and end points that they do.

As pseudo code:
For outerloop = 0 to array.ending_point - 1
  For innerloop = 1 to array.ending_point
    If innerloop.value = outerloop.value Then Duplicate.
  End innerloop
End outerloop

You have the logic there - I leave it to you to write the code.

Note - there are many more efficient methods to do this, but some of them don't match your criteria. You could sort the elements so you only need to check the next element to see if it's the same as this one (you'd only need one loop then). You could remove duplicate entries from the check so that you would ignore the elements later on that match as they would have been found by earlier iterations through the loop.
 
Share this answer
 
Ask Google about "map-reduce" algorithm. This will give you a way to identify all elements of the array, how many times each occurred and you only have to parse the array once.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900