Skip to content

Commit 8f5c3b9

Browse files
author
MasonCodingHere
committed
Update at Friday, October 11, 2024 PM05:14:09 HKT
1 parent d73ec77 commit 8f5c3b9

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

data-structures/Array/include/String.h

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,62 @@ class String{
4848
Vector<char> _data;
4949
};
5050

51-
5251
// Constructor and Desttructor
53-
String::String(){
52+
String::String() : _data() {}
53+
54+
String::~String(){
5455

5556
}
5657

57-
String::~String(){
58+
// Capacity
59+
bool String::empty() const{
60+
return _data.empty();
61+
}
62+
63+
size_t String::size() const{
64+
return _data.size();
65+
}
66+
67+
size_t String::length() const
68+
{
69+
return _data.size();
70+
}
71+
72+
size_t String::capacity() const{
73+
return _data.capacity();
74+
}
75+
76+
void String::reserve(const size_t n){
77+
_data.reserve(n);
78+
}
79+
80+
void String::resize(size_t n){
81+
_data.resize(n);
82+
}
83+
84+
void String::clear(){
85+
_data.clear();
86+
}
87+
88+
void String::shrink_to_fit(){
89+
_data.shrink_to_fit();
90+
}
91+
92+
// Elements access
93+
char& String::front(){
94+
return _data.front();
95+
}
96+
97+
char& String::back(){
98+
return _data.back();
99+
}
100+
101+
char& String::at(const size_t index){
102+
return _data.at(index);
103+
}
58104

105+
char& String::operator[](const size_t index){
106+
return _data[index];
59107
}
60108

61109
#endif // STRING_H

0 commit comments

Comments
 (0)