+ 1
Help me with analysis of code quality
Hi All, There are two vectors of string. Within vector also, there is a chance of duplicate values. Requirement is to have two vector merged so that result have only unique entries.One sample case is shown as input vector names1 and names2Order of elements in result is not important. I need your help to understand code quality. Can this code be more precise and of improved quality? below is code link: https://code.sololearn.com/cwcadBJfb1tb
2 Answers
+ 1
Yes, it is inefficient because you:
1. copy the whole content of both vectors
2. sort the new vector
3. look for iterators that contain duplicate contents
4. delete the iterators
These steps are redundant. You might want to look into a container called unordered_set that fits your task perfectly.
+ 1
Thanks Bobby Fischer ..updated code and could observe the difference in time taken... Thanks a lot đ