Last active
June 29, 2020 01:00
-
-
Save jmlyn/2fa4ecc94a94f33a9d07ac1e46439a1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Main.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
| // | |
| #include "pch.h" | |
| #include <crtdbg.h> | |
| #include "DynamicArray.h" | |
| #include "Queue.h" | |
| #include "SinglyLinkedList.h" | |
| #include "BinarySearchTree.h" | |
| #include "StdlibAlgorithmDemo.h" | |
| #include "MergeSort.h" | |
| #include "QuickSort.h" | |
| #include "HeapSort.h" | |
| #include "BubbleSort.h" | |
| #include "SelectionSort.h" | |
| #include "ShellSort.h" | |
| #include "CountingSort.h" | |
| #include "RadixSort.h" | |
| #include "BucketSort.h" | |
| #include "Dijkstra.h" | |
| #include "BreadthFirstSearch.h" | |
| int main() { | |
| _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); | |
| int arrayCapacity = 10; | |
| std::unique_ptr<std::unique_ptr<int>[]> uPtrArray = | |
| std::make_unique<std::unique_ptr<int>[]>(sizeof(int) * arrayCapacity); | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| uPtrArray[i] = std::make_unique<int>(0); | |
| } | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| *uPtrArray[i] = std::move(int(i)); | |
| } | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| std::cout << *uPtrArray[i] << " "; | |
| } | |
| std::cout << std::endl; | |
| // Increase array capacity: | |
| // Make copy | |
| int oldCapacity = arrayCapacity; | |
| arrayCapacity = 20; | |
| auto uPtrArrayCopy = std::make_unique<std::unique_ptr<int>[]>(sizeof(int) * arrayCapacity); | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| uPtrArrayCopy[i] = std::make_unique<int>(0); | |
| } | |
| for (int i = 0; i < oldCapacity; ++i) { | |
| uPtrArrayCopy[i] = std::move(uPtrArray[i]); | |
| } | |
| std::cout << "New array" << std::endl; | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| std::cout << *uPtrArrayCopy[i] << " "; | |
| } | |
| std::cout << std::endl; | |
| uPtrArray = std::move(uPtrArrayCopy); | |
| std::cout << "Original array after std::move" << std::endl; | |
| for (int i = 0; i < arrayCapacity; ++i) { | |
| std::cout << *uPtrArray[i] << " "; | |
| } | |
| std::cout << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment