Array.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include <iostream>
  3. using namespace std;
  4. const int DEFAULT_CAPACITY = 10;
  5. /// <summary>
  6. /// An array holding some integer values
  7. /// </summary>
  8. class Array
  9. {
  10. private:
  11. int* ptr;
  12. int size, capacity;
  13. /// <summary>
  14. /// Increase the capacity of the array
  15. /// </summary>
  16. /// <param name="newCapacity">New capacity</param>
  17. void increaseCapacity(int newCapacity);
  18. public:
  19. explicit Array(int startCapacity = DEFAULT_CAPACITY);
  20. Array(const Array&);
  21. ~Array();
  22. Array& operator = (const Array& arr);
  23. int& operator [] (int index);
  24. /// <summary>
  25. /// Insert element into position
  26. /// </summary>
  27. /// <param name="elem">The value to be inserted</param>
  28. /// <param name="index">The position to insert the value into</param>
  29. void insert(int elem, int index);
  30. /// <summary>
  31. /// Remove element from array
  32. /// </summary>
  33. /// <param name="index">The index of the element to be removed</param>
  34. void remove(int index);
  35. /// <summary>
  36. /// Get current size of the array
  37. /// </summary>
  38. /// <returns>The size of the array</returns>
  39. int getSize() const;
  40. friend ostream& operator <<(ostream& out, const Array& arr);
  41. };