Skip to content

Commit 105b2c4

Browse files
committed
wow ☁️
0 parents  commit 105b2c4

65 files changed

Lines changed: 3976 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.class
3+
*.o
4+
a.out
5+

Day1/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## DAY1 - (LinkedList, ArrayList, Stack, Queue)
2+
### 공부한것
3+
- LinkedList 등 기본적인 자료구조
4+
5+
### TODO
6+
- Stack
7+
- Infix 연산 -> Postfix 연산
8+
- Postfix 연산 계산하기
9+
10+
### 심화 내용
11+
- LinkedList 최적화
12+
- LinkedList에 루프가 있는지 체크 ( 플로이드 싸이클 )
13+
- 뒤에서 n번째 노드 찾기
14+
15+
16+

Day1/c++/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
test_list:
2+
g++ -O3 -std=c++11 test_list.cpp -o test_list && ./test_list
3+
4+
test_stack:
5+
g++ test_stack.cpp -o test_stack && ./test_stack
6+
7+
all: test_list test_stack
8+
9+
clean:
10+
rm -rf test_list test_stack
11+
12+
.PHONY: all test_list test_stack

Day1/c++/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### 목표
2+
- STL 과 비슷한 자료구조를 만들어보기
3+
4+
### TODO
5+
- 메모리 관리 해야댐..

Day1/c++/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __JY_H__
2+
#define __JY_H__
3+
4+
namespace jy{
5+
template<typename T>
6+
struct is_pointer { static const bool value = false; };
7+
8+
template<typename T>
9+
struct is_pointer<T*> { static const bool value = true; };
10+
}
11+
12+
#endif

Day1/c++/list.hpp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
//
2+
// list.hpp
3+
// MemoryTest
4+
//
5+
// Created by Rangken on 2014. 9. 12..
6+
// Copyright (c) 2014년 test. All rights reserved.
7+
//
8+
9+
#ifndef __JY_LIST_HPP__
10+
#define __JY_LIST_HPP__
11+
#include <iostream>
12+
#include "common.h"
13+
14+
using namespace std;
15+
namespace jy{
16+
17+
template <class T>
18+
class Node{
19+
public:
20+
T element;
21+
Node* next;
22+
Node* prev;
23+
Node(){
24+
25+
}
26+
virtual ~Node(){
27+
28+
}
29+
};
30+
31+
32+
template <class T>
33+
class list{
34+
public:
35+
36+
class iterator{
37+
public:
38+
iterator() : current(NULL){}
39+
T& operator++(){
40+
// 전위 증감
41+
Node<T>* temp = current;
42+
current = current->next;
43+
44+
return temp->element;
45+
}
46+
T operator++(int){
47+
// 후위 증감
48+
}
49+
T& operator*(){
50+
return current->element;
51+
}
52+
bool operator==(const iterator& b) const{
53+
54+
if(current == b.current){
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
bool operator!=(const iterator& b) const{
61+
if(current == b.current){
62+
return false;
63+
}
64+
return true;
65+
}
66+
private:
67+
Node<T>* current;
68+
iterator(Node<T>* _node) : current(_node){}
69+
70+
friend class list<T>; // list 에서 iterator private 에 접근 가능하도록
71+
};
72+
list(){
73+
// 생성자
74+
// cout << "list() called" << endl;
75+
head = NULL;
76+
}
77+
explicit list(const T& t){
78+
// 복사생성자 암시적 캐스팅은 방지(explicit)
79+
head = NULL;
80+
}
81+
~list(){
82+
83+
}
84+
void push_back(const T& t){
85+
// list <int> 스택변수에서 불러짐
86+
if(head == NULL){
87+
head = new Node<T>();
88+
head->element = t;
89+
head->next = NULL;
90+
head->prev = NULL;
91+
}else{
92+
Node<T>* node = new Node<T>();
93+
node->element = t;
94+
node->next = NULL;
95+
96+
Node<T>* tail = tailNode();
97+
tail->next = node;
98+
node->prev = tail;
99+
}
100+
}
101+
void push_back(T&& t){
102+
// list <int*> 이면서 int a; list.push_back(&a); 일때 불러짐
103+
if(head == NULL){
104+
head = new Node<T>();
105+
head->element = t;
106+
head->next = NULL;
107+
head->prev = NULL;
108+
}else{
109+
Node<T>* node = new Node<T>();
110+
node->element = t;
111+
node->next = NULL;
112+
113+
Node<T>* tail = tailNode();
114+
tail->next = node;
115+
node->prev = tail;
116+
}
117+
}
118+
void pop_back(){
119+
Node<T>* temp = tailNode();
120+
if(temp->prev){
121+
temp->prev->next = NULL;
122+
}
123+
delete temp;
124+
}
125+
T front(){
126+
return head->element;
127+
}
128+
T back(){
129+
Node<T>* temp = tailNode();
130+
return temp->element;
131+
}
132+
iterator begin(){
133+
return iterator(head);
134+
}
135+
136+
iterator end(){
137+
Node<T>* temp = head;
138+
while(temp){
139+
temp = temp->next;
140+
}
141+
return iterator(temp);
142+
}
143+
144+
void display(){
145+
Node<T>* temp = head;
146+
while(temp){
147+
cout << temp << endl;
148+
temp = temp->next;
149+
}
150+
}
151+
private:
152+
Node<T>* head;
153+
Node<T>* frontNode(){
154+
return head;
155+
}
156+
Node<T>* tailNode(){
157+
Node<T>* temp = head;
158+
while(temp->next){
159+
temp = temp->next;
160+
}
161+
return temp;
162+
}
163+
};
164+
}
165+
166+
#endif

Day1/c++/test_list

15.5 KB
Binary file not shown.

Day1/c++/test_list.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include "list.hpp"
3+
4+
using namespace std;
5+
using namespace jy;
6+
7+
int main(int argc, char* argv[]){
8+
cout << "----- list -----" << endl;
9+
cout << "----- list<int> -----" << endl;
10+
list<int> t;
11+
int a = 1;
12+
int b = 2;
13+
int c = 3;
14+
15+
t.push_back(a);
16+
t.push_back(b);
17+
t.push_back(c);
18+
19+
t.pop_back();
20+
21+
for(list<int>::iterator iter = t.begin(); iter != t.end(); ++iter){
22+
cout << *iter << endl;
23+
}
24+
25+
cout << "----- list<int*> -----" << endl;
26+
list<int*> t2;
27+
int *pa = new int();
28+
*pa = 4;
29+
int *pb = new int();
30+
*pb = 5;
31+
int *pc = new int();
32+
*pc = 6;
33+
34+
t2.push_back(pa);
35+
t2.push_back(pb);
36+
t2.push_back(pc);
37+
38+
t2.pop_back();
39+
40+
for(list<int*>::iterator iter = t2.begin(); iter != t2.end(); ++iter){
41+
cout << **iter << endl;
42+
}
43+
return 1;
44+
}
45+

Day1/c++/test_stack.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include "list.hpp"
3+
4+
using namespace std;
5+
using namespace jy;
6+
7+
int main(int argc, char* argv[]){
8+
cout << "----- list -----" << endl;
9+
cout << "----- list<int> -----" << endl;
10+
list<int> t;
11+
int a = 1;
12+
int b = 2;
13+
int c = 3;
14+
15+
t.push_back(a);
16+
t.push_back(b);
17+
t.push_back(c);
18+
19+
for(list<int>::iterator iter = t.begin(); iter != t.end(); ++iter){
20+
cout << *iter << endl;
21+
}
22+
23+
cout << "----- list<int*> -----" << endl;
24+
list<int*> t2;
25+
int *pa = new int();
26+
*pa = 4;
27+
int *pb = new int();
28+
*pb = 5;
29+
int *pc = new int();
30+
*pc = 6;
31+
32+
t2.push_back(pa);
33+
t2.push_back(pb);
34+
t2.push_back(pc);
35+
for(list<int*>::iterator iter = t2.begin(); iter != t2.end(); ++iter){
36+
cout << **iter << endl;
37+
}
38+
return 1;
39+
}
40+

0 commit comments

Comments
 (0)