If there is the following vector1:
vector<string*> cont; // cont[0] == "0"
where pointers to strings are named either l
or r
; are sequentially added like so:
string r* = new string("1");
cont.emplace_back(r);
or:
string l* = new string("-1");
cont.emplace_back(l);
For example: if there is a direction to a node given like: "lrlrrr"
.
Is there a way to search through the vector using the string names, l
and r
, as "element id" rather than string content2?
Note: I've researched finding a vector element by native property, however, I'm interested if there is alternative way.
1. The vector stores sequentially (level by level) the nodes of a binary tree, where each left node's,l
, value is: parent value - 1 and each right node's, r
, value is: parent value + 1.
2. Comparing current and previous node values determines if current node left or right.