Quick Refresh — Competitive Coding (C++)
Now that we have familiarized with the basics, let’s leap into couple of use cases and examples. Here’s how I’ve setup the show.
All set! now the first not so much of a container pair, whose main intention is to group two items. you can make a array out of it, or even better.. ‘pair’ it along with vectors as we see next..
As they say DDoS is better than Dos, we are pretty much limited with just a pair, so let’s see how an army of pairs look like.. introducing Vectors.
These operations on vectors happen at O(1) which we competitive programmers love to hear, unless you’re copying one which becomes O(n). Point to mention here is that we are free to create a much complex datastructure. However, in most use cases, they aren’t required…
Simplicity is the key.
Now that we know how to add elements at the end, a curious individual would want to insert an element in between.. as so we have Iterators.
Similar to pointers, these point to the elements of a container, defined as
- These are just a fraction of what iterators do, and every container has its own iterator with other functions.
- The auto keyword, introduced in C++11, dynamically sets the type of the variable, hence not requiring us to type the spells.
Up next, we’ll be looking into Sets, Maps, different types of it and so on..
-See you in Part III