-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.h
More file actions
46 lines (38 loc) · 1.66 KB
/
Vector.h
File metadata and controls
46 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//--------------------------------------------------------------------
//
// Homework Vector.h
//
// Class declaration for the array implementation of the Vector ADT
//
//--------------------------------------------------------------------
#ifndef VECTOR_H
#define VECTOR_H
using namespace std;
template <class DataType>
class Vector
{
public:
// Constructors
Vector(); // Default constructor
// Destructor
~Vector();
// Vector manipulation operations
void append(const DataType item); // Add a new item to the end of the vector
void insertAt(const int index, const DataType item); // Insert a new element at the given index
void removeAt(const int index); // Remove the data item at the given index
void remove(int item); // Remove the given element from the vector
void clear(); // Make the vector empty
// Vector status operations
bool isEmpty() const; // Is the Vector empty?
bool isFull() const; // Is the Vector full?
int contains(const DataType item) const; // Does the vector contain the given item? return the index of the item if found, otherwise, return -1.
DataType elementAt(const int index) const; // Access the element at the given index
int getSize() const; // Return the number of items in the vector
DataType &operator[] (const int index); // overloading subscript []
private:
// Data members
int capacity; // the capacity of the vector
int size; // Actual number of data item in the vector
DataType *dataItems; // Array containing the vector data item
};
#endif