Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

print duplicate names in an array

OpenStudy (p0sitr0n):

assuming C++/Java style languages and an array sorted in alphabetical order int duplicate(String* names[]){ String[] names=&names; String[] dup; for (int i=0;i<names.size();i++) { if (names[i].compare(names[i+1])) { cout << "duplicate name at "<<i<<endl; dup[i]=names[i]; } else { dup[i]=NULL; } } return 0; } //Basically this method takes a sorted array of n elements (names) in alphabetical order and then compares two adjacent names. If they are the same, we push it onto the duplicate array. If not, we push NULL. Then all you have to do is to read the duplicate array for any non-NULL name.

OpenStudy (anonymous):

Thank you soo much

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!