Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The method noMatch whose heading is:

public static boolean noMatch(Queue <integer> q)

Takes a queue of items 'q' and returns true if and only if all the elements contained in q are all different, and false otherwise.

IF Q contains: 1,2,3,4,5,6,7. THEN noMatch returns true.
IF Q contains:1,2,3,4,5,6,7,7,7 THEN noMatch returns false.

How can this be implemented successfully?
Posted
Updated 15-Nov-14 21:49pm
v2

1 solution

Assuming the size of the queue is unknown, and could be large - the simplest solution is to sort them: Then duplicates are together and can be spotted easily just by comparing adjacent values.

But since this is your homework, I'll give you no code, and teh implementation is up to you.
It is a trivial task though!
 
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