Skip to content
KROIA edited this page May 22, 2018 · 7 revisions

Vector(unsigned int size = 0);

Description

  • Constructor
  • size predefined a size of the Array

Syntax

  • Vector<int> myVector;
  • Vector<String> myVector;
  • You can choose any type as a Vector

~Vector();

Description

  • Deletes all saved data in the array.

Syntax

  • delete &myVector;

void push_back(T element);

Description

  • Adds an element to the array.

Syntax

  • myVector.push_back(15);

T& pop_back();

Description

  • Returns the last last element of the array.
  • Deletes the last element in the array.
  • Decreses the size of the array.

Syntax

  • int value = myVector.pop_back();

unsigned int size();

Description

  • Gets the size of the array.

Syntax

  • unsigned int size = myVector.size();

void resize(unsigned int size);

Description

  • Resizes the array.
  • Used to make the push_back() faster.
  • Reservs storage for size elements.

unsigned int capacity();

Description

  • returns the actual size of the array which is reserved in storage.

example

  • Vector<int> myVector;
  • myVector.resize(5);
  • myVector.size() == 0
  • myVector.capacity() == 5
  • When an element is pushed back the size won't increase until capacity <= size.
  • myVector.push_back(1);
  • myVector.size() == 1
  • myVector.capacity() == 5

void erase(unsigned int pos,unsigned int amount = 1);

Description

  • Erase a sequence of elements in the array.
  • Beginning from element pos.
  • From there on deletes amount elements.

Syntax

  • myVector.erase(2,3); Erases the elements: [-]: [x][x][-][-][-][x][x]
  • myVector.erase(2); Erases the element: [-]: [x][x][-][x][x][x][x]

void clear();

Description

  • Clears the whole array.
  • All elements get deleted.

Syntax

  • myVector.clear();

T* begin();

Description

  • Gets the pointer of the first element in the array.
  • Don't use it in myVector.erase(myVector.begin());

Syntax

  • int *p_int = myVector.begin();
Clone this wiki locally