-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharArrayList.h
More file actions
77 lines (72 loc) · 2.64 KB
/
CharArrayList.h
File metadata and controls
77 lines (72 loc) · 2.64 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* CharArrayList.h
* Edgar Gonzalez
* 2026-01-28
*
*
* FILE PURPOSE HERE
*
*/
#ifndef CHAR_ARRAY_LIST_H
#define CHAR_ARRAY_LIST_H
#include <string>
#include <chrono>
class CharArrayList {
public:
CharArrayList();
// Default Constructor
CharArrayList(char c);
// Constructor for single character
CharArrayList(char arr[], int size);
// Constructor for array of characters
CharArrayList(const CharArrayList &other);
// Copy Constructor
~CharArrayList();
//Deconstructor
CharArrayList& operator=(const CharArrayList &other);
//Assignment Operator overload
void clear();
//Clears the CharArrayList
bool isEmpty() const;
//Checks if the CharArrayList is empty
int size() const;
//Returns the number of elements in the CharArrayList
char first() const;
//Returns the first element in the CharArrayList
char last() const;
//Returns the last element in the CharArrayList
char elementAt(int index) const;
//Returns the element at a specified index
std::string toString() const;
//String representation of CharArrayList
std::string toReverseString() const;
//String representation of CharArrayList in reverse order
void pushAtBack(char c);
//Adds a character to the back of the CharArrayList
void pushAtFront(char c);
//Adds a character to the front of the Char
void insertAt(char c, int index);
//Inserts a character at a specified index
void insertInOrder(char c);
//Inserts a character in order (assuming the list is sorted)
void popFromFront();
//Removes the first character from the CharArrayList
void popFromBack();
//Removes the last character from the CharArrayList
void removeAt(int index);
//Removes the character at a specified index
void replaceAt(char c, int index);
//Replaces the character at a specified index with a new character
void concatenate(const CharArrayList *other);
//Concatenates another CharArrayList
private:
int capacity;
//maximum number of elements the CharArrayList can hold
int numItems;
//number of elements in the CharArrayList
char* data;
//pointer to dynamic array of characters
void ensureCapacity();
//doubles the capacity of the CharArrayList when needed
};
#endif