mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
New Core Tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dd88feaf2e
commit
6c22e727de
37 changed files with 3125 additions and 0 deletions
46
tutorial/CoreTutorial/Vector2.cpp
Normal file
46
tutorial/CoreTutorial/Vector2.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void Vector2()
|
||||
{
|
||||
/// .`Vector` operations
|
||||
|
||||
/// You can `Insert` or `Remove` elements at random positions of Vector (O(n) complexity):
|
||||
|
||||
Vector<int> v;
|
||||
v.Add(1);
|
||||
v.Add(2);
|
||||
|
||||
v.Insert(1, 10);
|
||||
|
||||
DUMP(v);
|
||||
|
||||
///
|
||||
|
||||
v.Insert(0, { 7, 6, 5 });
|
||||
|
||||
DUMP(v);
|
||||
|
||||
///
|
||||
|
||||
v.Remove(0);
|
||||
|
||||
DUMP(v);
|
||||
|
||||
/// At method returns element at specified position ensuring that such a position exists.
|
||||
/// If there is not enough elements in `Vector`, required number of elements is added. If
|
||||
/// second parameter of `At` is present, newly added elements are initialized to this value.
|
||||
|
||||
v.Clear();
|
||||
for(int i = 0; i < 10000; i++)
|
||||
v.At(Random(10), 0)++;
|
||||
|
||||
DUMP(v);
|
||||
|
||||
/// You can apply algorithms on containers, e.g. Sort
|
||||
|
||||
Sort(v);
|
||||
|
||||
DUMP(v);
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue