Skip to content

Commit b9c886f

Browse files
author
Sein Lee
authored
Revert "Feature/array list"
1 parent f450162 commit b9c886f

File tree

12 files changed

+116
-251
lines changed

12 files changed

+116
-251
lines changed

ArrayList/ArrayList.h

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class ArrayList
1717

1818
explicit ArrayList(const std::initializer_list<T> args) noexcept;
1919

20-
ArrayList(const ArrayList& src);
21-
ArrayList(ArrayList&& src) noexcept;
22-
2320
~ArrayList() noexcept;
2421

2522
void add(const T& value);
@@ -31,9 +28,7 @@ class ArrayList
3128

3229
const T* const getRaw() const;
3330
T* const getRaw();
34-
35-
ArrayList& operator=(const ArrayList& rhs);
36-
ArrayList& operator==(ArrayList&& rhs) noexcept;
31+
3732
T& operator[](const size_t index);
3833

3934
void show(const std::string& name) const;
@@ -62,37 +57,13 @@ ArrayList<T>::ArrayList(const std::initializer_list<T> args) noexcept
6257
__init(args);
6358
}
6459

65-
template<typename T>
66-
ArrayList<T>::ArrayList(const ArrayList& src)
67-
{
68-
const size_t size = src.__size;
69-
70-
if (size)
71-
{
72-
const size_t memSize = (sizeof(T) * size);
73-
74-
__malloc(src.__size);
75-
memcpy(__pMemory, src.__pMemory, memSize);
76-
}
77-
}
78-
79-
template<typename T>
80-
ArrayList<T>::ArrayList(ArrayList&& src) noexcept
81-
{
82-
std::swap(__pMemory, src.__pMemory);
83-
84-
__size = src.__size;
85-
__capacity = src.__capacity;
86-
}
87-
8860
template <typename T>
8961
ArrayList<T>::~ArrayList() noexcept
9062
{
9163
__size = 0ULL;
9264
__capacity = 0ULL;
9365

94-
if (__pMemory)
95-
__free();
66+
__free();
9667
}
9768

9869
template <typename T>
@@ -182,40 +153,6 @@ T* const ArrayList<T>::getRaw()
182153
return __pMemory;
183154
}
184155

185-
template<typename T>
186-
ArrayList<T>& ArrayList<T>::operator=(const ArrayList& rhs)
187-
{
188-
if (this == &rhs)
189-
return *this;
190-
191-
if (__pMemory)
192-
__free();
193-
194-
const size_t size = rhs.__size;
195-
196-
if (size)
197-
{
198-
const size_t memSize = (sizeof(T) * size);
199-
200-
__malloc(size);
201-
memcpy(__pMemory, rhs.__pMemory, memSize);
202-
}
203-
204-
return *this;
205-
}
206-
207-
template<typename T>
208-
ArrayList<T>& ArrayList<T>::operator==(ArrayList&& rhs) noexcept
209-
{
210-
if (this == &rhs)
211-
return *this;
212-
213-
__size = rhs.__size;
214-
__capacity = rhs.__capacity;
215-
216-
std::swap(__pMemory, rhs.__pMemory);
217-
}
218-
219156
template <typename T>
220157
T& ArrayList<T>::operator[](const size_t index)
221158
{
@@ -239,8 +176,11 @@ void ArrayList<T>::show(const std::string& name) const
239176
template<typename T>
240177
void ArrayList<T>::__free()
241178
{
242-
delete[] __pMemory;
243-
__pMemory = nullptr;
179+
if (__pMemory)
180+
{
181+
delete[] __pMemory;
182+
__pMemory = nullptr;
183+
}
244184
}
245185

246186
template<typename T>

ArrayList/ArrayList.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
</PropertyGroup>
2020
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2121
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
22-
<ConfigurationType>StaticLibrary</ConfigurationType>
22+
<ConfigurationType>Application</ConfigurationType>
2323
<UseDebugLibraries>true</UseDebugLibraries>
2424
<PlatformToolset>v142</PlatformToolset>
2525
<CharacterSet>Unicode</CharacterSet>
2626
</PropertyGroup>
2727
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
28-
<ConfigurationType>StaticLibrary</ConfigurationType>
28+
<ConfigurationType>Application</ConfigurationType>
2929
<UseDebugLibraries>false</UseDebugLibraries>
3030
<PlatformToolset>v142</PlatformToolset>
3131
<WholeProgramOptimization>true</WholeProgramOptimization>
@@ -84,7 +84,7 @@
8484
</Link>
8585
</ItemDefinitionGroup>
8686
<ItemGroup>
87-
<ClCompile Include="dummy.cpp" />
87+
<ClCompile Include="main.cpp" />
8888
</ItemGroup>
8989
<ItemGroup>
9090
<ClInclude Include="ArrayList.h" />

ArrayList/ArrayList.vcxproj.filters

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<ClInclude Include="ArrayList.h" />
55
</ItemGroup>
66
<ItemGroup>
7-
<ClCompile Include="dummy.cpp" />
7+
<ClCompile Include="main.cpp" />
88
</ItemGroup>
99
</Project>

ArrayList/dummy.cpp

Whitespace-only changes.

ArrayList/main.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <vector>
2+
#include "ArrayList.h"
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
/*
9+
아래의 코드를 모두 정상적으로 실행할 수 있는 ArrayList를 구현하여라.
10+
ArrayList는 std::vector와 동일한 동작을 수행한다.
11+
12+
구현시 아래의 명세를 모두 만족하시오.
13+
14+
1.
15+
ArrayList의 원소는 임의로 설정 가능하다. (템플릿화 할 것)
16+
17+
2.
18+
ArrayList의 메모리는 항상 단일 블록으로 구성되어 있다. 즉 배열과 같이,
19+
메모리가 쪼개져있지 않고 쭉 이어져 있다.
20+
21+
3.
22+
스마트 포인터를 사용하지 않고, new/delete만을 이용하여 메모리를 관리하여라.
23+
*/
24+
25+
/*
26+
초기 크기 3의 리스트 생성.
27+
이 때 원소의 값은 타입 파라미터의 기본 값으로 설정.
28+
int가 아닌 다른 값(float, double, 심지어 string까지) 모두 기본 값으로 초기화 되어야 한다.
29+
30+
소괄호() 가 아닌 중괄호{} 로 생성자를 호출하는 uniform initializer에 대해 조사하여 글을 정리하여라.
31+
*/
32+
ArrayList<int> list1 { 3 };
33+
34+
// operator[] 를 구현하여 index에 따라 해당 원소를 접근할 수 있도록 하여라.
35+
int& first = list1[0];
36+
first = 10;
37+
38+
// TEST 1
39+
list1.show("list1");
40+
41+
// initializer list를 활용하여 원소 3개를 삽입하며 초기화
42+
// initializer list에 대해 조사하여 글을 정리하여라.
43+
ArrayList<string> list2{ "elem1", "elem2", "elem3" };
44+
45+
// TEST 2
46+
list2.show("list2");
47+
48+
// list의 뒤쪽에 elem4, elem5를 추가
49+
list2.add("elem4");
50+
list2.add("elem5");
51+
52+
// size_t 타입의 element size를 반환. (5가 출력되어야 함)
53+
cout << list2.getSize() << endl;
54+
55+
// 1번째 원소 (elem2)를 삭제한다.
56+
const size_t removeIndex = 1ULL;
57+
list2.remove(removeIndex);
58+
59+
// 4 출력
60+
cout << list2.getSize() << endl;
61+
62+
// elem3 출력
63+
cout << list2.get(1ULL) << endl;
64+
65+
// 1번째 위치에 "elem5" 삽입
66+
const size_t insertIndex = 1ULL;
67+
list2.insert(insertIndex, "elem5");
68+
69+
// "elem5" 출력
70+
cout << list2[1] << endl;
71+
72+
// "elem3" 출력
73+
cout << list2[2] << endl << endl;
74+
75+
// TEST 3
76+
const int list1Size = int(list1.getSize());
77+
ArrayList<int> list3{ list1Size };
78+
{
79+
memcpy(list3.getRaw(), list1.getRaw(), sizeof(int) * list1Size);
80+
list3.show("list3");
81+
}
82+
83+
// TEST 4
84+
ArrayList<int> list4;
85+
{
86+
list4.insert(0ULL, 5);
87+
list4.show("list4");
88+
}
89+
90+
// TEST 5
91+
ArrayList<string> list5 { 6 };
92+
93+
return 0;
94+
}

Client/Client.vcxproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@
7070
<ClCompile Include="main.cpp" />
7171
</ItemGroup>
7272
<ItemGroup>
73-
<ProjectReference Include="..\ArrayList\ArrayList.vcxproj">
74-
<Project>{5f928571-411f-4f81-b1a4-e18f15efdda4}</Project>
75-
</ProjectReference>
76-
<ProjectReference Include="..\StaticCalculator\StaticCalculator.vcxproj">
77-
<Project>{b2be17ee-02ae-4158-b453-12b7e517abf0}</Project>
78-
</ProjectReference>
7973
<ProjectReference Include="..\Var\Var.vcxproj">
8074
<Project>{2d566859-9659-40ea-bb45-a9add4a74ccf}</Project>
8175
</ProjectReference>

Client/main.cpp

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
using namespace std;
44

5-
static int varMain();
6-
static int staticCalculatorMain();
7-
static int arrayListMain();
5+
int varMain();
6+
int staticCalculatorMain();
87

98
int main()
109
{
11-
int (*fp[])() =
12-
{
13-
varMain,
14-
staticCalculatorMain,
15-
arrayListMain
16-
};
17-
18-
return fp[2]();
10+
int (*fp[2])() = { varMain, staticCalculatorMain };
11+
12+
return fp[1]();
1913
}
2014

2115
// --------------------------- Var
@@ -179,99 +173,5 @@ int staticCalculatorMain()
179173
// 크기 7인 배열 생성
180174
int arr[calcResult2]{};
181175

182-
return 0;
183-
}
184-
185-
// --------------------------- ArrayList
186-
187-
#include "../ArrayList/ArrayList.h"
188-
189-
int arrayListMain()
190-
{
191-
/*
192-
아래의 코드를 모두 정상적으로 실행할 수 있는 ArrayList를 구현하여라.
193-
ArrayList는 std::vector와 동일한 동작을 수행한다.
194-
195-
구현시 아래의 명세를 모두 만족하시오.
196-
197-
1.
198-
ArrayList의 원소는 임의로 설정 가능하다. (템플릿화 할 것)
199-
200-
2.
201-
ArrayList의 메모리는 항상 단일 블록으로 구성되어 있다. 즉 배열과 같이,
202-
메모리가 쪼개져있지 않고 쭉 이어져 있다.
203-
204-
3.
205-
스마트 포인터를 사용하지 않고, new/delete만을 이용하여 메모리를 관리하여라.
206-
*/
207-
208-
/*
209-
초기 크기 3의 리스트 생성.
210-
이 때 원소의 값은 타입 파라미터의 기본 값으로 설정.
211-
int가 아닌 다른 값(float, double, 심지어 string까지) 모두 기본 값으로 초기화 되어야 한다.
212-
213-
소괄호() 가 아닌 중괄호{} 로 생성자를 호출하는 uniform initializer에 대해 조사하여 글을 정리하여라.
214-
*/
215-
ArrayList<int> list1{ 3 };
216-
217-
// operator[] 를 구현하여 index에 따라 해당 원소를 접근할 수 있도록 하여라.
218-
int& first = list1[0];
219-
first = 10;
220-
221-
// TEST 1
222-
list1.show("list1");
223-
224-
// initializer list를 활용하여 원소 3개를 삽입하며 초기화
225-
// initializer list에 대해 조사하여 글을 정리하여라.
226-
ArrayList<string> list2{ "elem1", "elem2", "elem3" };
227-
228-
// TEST 2
229-
list2.show("list2");
230-
231-
// list의 뒤쪽에 elem4, elem5를 추가
232-
list2.add("elem4");
233-
list2.add("elem5");
234-
235-
// size_t 타입의 element size를 반환. (5가 출력되어야 함)
236-
cout << list2.getSize() << endl;
237-
238-
// 1번째 원소 (elem2)를 삭제한다.
239-
const size_t removeIndex = 1ULL;
240-
list2.remove(removeIndex);
241-
242-
// 4 출력
243-
cout << list2.getSize() << endl;
244-
245-
// elem3 출력
246-
cout << list2.get(1ULL) << endl;
247-
248-
// 1번째 위치에 "elem5" 삽입
249-
const size_t insertIndex = 1ULL;
250-
list2.insert(insertIndex, "elem5");
251-
252-
// "elem5" 출력
253-
cout << list2[1] << endl;
254-
255-
// "elem3" 출력
256-
cout << list2[2] << endl << endl;
257-
258-
// TEST 3
259-
const int list1Size = int(list1.getSize());
260-
ArrayList<int> list3{ list1Size };
261-
{
262-
memcpy(list3.getRaw(), list1.getRaw(), sizeof(int) * list1Size);
263-
list3.show("list3");
264-
}
265-
266-
// TEST 4
267-
ArrayList<int> list4;
268-
{
269-
list4.insert(0ULL, 5);
270-
list4.show("list4");
271-
}
272-
273-
// TEST 5
274-
ArrayList<string> list5{ 6 };
275-
276176
return 0;
277177
}

StaticCalculator/StaticCalculator.vcxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@
147147
<ClInclude Include="OperationType.h" />
148148
<ClInclude Include="StaticCalculator.h" />
149149
</ItemGroup>
150-
<ItemGroup>
151-
<ClCompile Include="dummy.cpp" />
152-
</ItemGroup>
153150
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
154151
<ImportGroup Label="ExtensionTargets">
155152
</ImportGroup>

0 commit comments

Comments
 (0)