I have a deque:
deque<char> My_Deque;
My_Path.push_front('a');
My_Path.push_front('b');
My_Path.push_front('c');
My_Path.push_front('d');
My_Path.push_front('e');
There are such ways to output it.
The first:
deque<char>::iterator It;
for ( It = My_Deque.begin(); It != My_Deque.end(); It++ )
cout << *It << " ";
The second:
for (i=0;i<My_Deque.size();i++) {
cout << My_Deque[i] << " ";
}
What is the best way to access deque's element - through iterator or like this: My_Deque[i]
?
Has a deque<...> element an array of pointers to each element for fast access to it's data or it provides access to it's random element in consequtive way (like on a picture below)?
Since you asked for "the best way":
for (char c : My_Deque) { std::cout << c << " "; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With