Most efficient way to find an entry in a C++ vector
up vote
7
down vote
favorite
2
I'm trying to construct an output table containing 80 rows of table status, that could be EMPTY or USED as below +-------+-------+ | TABLE | STATE | +-------+-------+ | 00 | USED | | 01 | EMPTY | | 02 | EMPTY | .. .. | 79 | EMPTY | +-------+-------+ I have a vector m_availTableNums which contains a list of available table numbers. In the below example, I'm putting 20 random table numbers into the above vector such that all the remaining 60 would be empty. My logic below works fine. Is there a scope for improvement here on the find logic? #include <iostream> #include <iomanip> #include <cmath> #include <string.h> #include <cstdlib> #include <vector> #include <algorithm> #include <ctime> using namespace std...