Add containers module with initial implementation and integrate into CMake build system.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
typedef std::list<float> FloatList;
|
||||
typedef FloatList::iterator FloatListIterator;
|
||||
|
||||
int main() {
|
||||
// C array
|
||||
int numbers[5] = {1, 2, 3, 4, 5}; // stack array
|
||||
const int count = 10;
|
||||
// count *= 2;
|
||||
int numbers2[count];
|
||||
numbers2[0] = 10;
|
||||
|
||||
int* numbers3 = new int[count]; // heap array
|
||||
delete[] numbers3;
|
||||
numbers3 = nullptr;
|
||||
|
||||
// numbers[10] = 100;
|
||||
|
||||
std::cout << "size of numbers: " << sizeof(numbers) << std::endl;
|
||||
|
||||
printArrayAtPosition(numbers, 19);
|
||||
|
||||
// vector
|
||||
std::vector<int> v;
|
||||
v.push_back(10);
|
||||
v.push_back(20);
|
||||
v.push_back(30);
|
||||
v.pop_back();
|
||||
v[1] = 100;
|
||||
|
||||
std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
v.push_back(40);
|
||||
|
||||
std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
v.push_back(50);
|
||||
|
||||
std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
v.push_back(60);
|
||||
|
||||
std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
v.reserve(100);
|
||||
|
||||
std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
printArrayAtPosition(v.data(), 1);
|
||||
|
||||
// list
|
||||
std::list<int> l;
|
||||
std::list<int>::iterator it;
|
||||
|
||||
for (it = l.begin(); it != l.end(); ++it) {
|
||||
std::cout << *it << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user