Skip to content

Commit 499648a

Browse files
committed
queue
1 parent a696e0f commit 499648a

File tree

6 files changed

+195
-1
lines changed

6 files changed

+195
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
1. [stack(linked list)](./stack/stack_linked_list)
1313
1. [baekjoon](./stack#baekjoon)
1414
1. [생각해보기](./stack#생각해보기)
15-
1. queue & deque
15+
1. [queue](./queue)
16+
1. [queue(array)](./queue/queue_array)
17+
1. [queue(linked list)](./queue/queue_linked_list)
18+
1. [baekjoon](./queue#baekjoon)
19+
1. [생각해보기](./queue#생각해보기)
20+
1. [deque](./deque)
21+
1. [deque(array)](./deque/deque_array)
22+
1. [deque(linked list)](./deque/deque_linked_list)
23+
1. [baekjoon](./deque#baekjoon)
24+
1. [생각해보기](./deque#생각해보기)
1625
1. tree
26+
1. binary tree
1727
1. priority queue, heap
1828
1. sort
1929
1. hash
2030
1. graph
31+
1. 최소신장트리
32+
1. 최단거리 알고리즘
33+
- 다익스트라
34+
2135

2236
## coding convention
2337
- 우선순위는 가독성, 성능, 짧은 코드 순으로 한다.

queue/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Queue
2+
3+
[뒤로 가기](https://github.com/nadarm/42-algo-basic)
4+
5+
## index
6+
1. [queue(array)](./queue_array)
7+
1. [queue(linked list)](./queue_linked_list)
8+
1. [baekjoon](#baekjoon)
9+
1. [생각해보기](#생각해보기)
10+
11+
## baekjoon
12+
- [18258번 큐 2](https://www.acmicpc.net/problem/18258)
13+
- [2164번 카드2](https://www.acmicpc.net/problem/2164)
14+
- [1966번 프린터 큐](https://www.acmicpc.net/problem/1966)
15+
16+
## 생각해보기
17+
- queue를 array로 구현 했을 때와 linked list로 구현 했을 때의 장단점
18+
- queue가 사용되는 상황
19+
- array로 queue를 효율성 있게 구현하려면?
20+
21+
22+
[뒤로 가기](https://github.com/nadarm/42-algo-basic)

queue/queue_array/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Queue(Array)
2+
3+
[뒤로 가기](..)
4+
5+
## exercise 00
6+
- array를 사용하여 queue을 구현 합니다.
7+
- 아래와 같은 queue.h를 사용 합니다.
8+
```
9+
typedef struct s_queue
10+
{
11+
unsigned int max_size;
12+
int last_index;
13+
void **data;
14+
} t_queue;
15+
```
16+
17+
### queue_init
18+
- t_queue형 struct를 반환 하는 함수를 작성하세요.
19+
- 반환되는 t_queue는 메모리 할당과 초기화를 거쳐야합니다.
20+
```
21+
t_queue *queue_init(unsigned int max_size);
22+
```
23+
24+
### queue_push
25+
- queue의 가장 뒤에 data를 추가하는 함수를 작성하세요.
26+
- 성공하면 1, 실패하면 0을 반환 합니다.
27+
```
28+
int queue_push(t_queue *queue, void *data);
29+
```
30+
31+
### queue_size
32+
- queue에 있는 요소의 개수를 반환하는 함수를 작성하세요.
33+
```
34+
int queue_size(t_queue *queue);
35+
```
36+
37+
### queue_front
38+
- queue에서 가장 앞에 있는 data를 반환하는 함수를 작성하세요.
39+
```
40+
void *queue_front(t_queue *queue);
41+
```
42+
43+
### queue_pop
44+
- queue에서 가장 앞에 있는 data를 꺼내는 함수를 작성하세요.
45+
```
46+
void *queue_pop(t_queue *queue);
47+
```
48+
49+
### queue_clear
50+
- queue의 data 전체를 삭제하는 함수를 작성하세요.
51+
- data는 free_data를 사용해서 메모리 할당을 해제해야 합니다.
52+
```
53+
void queue_clear(t_queue *queue, void (*free_data)(void *));
54+
```
55+
56+
### free_queue
57+
- queue에 있는 data 전체를 삭제하고 queue의 메모리 할당을 해제하는 함수를 작성하세요.
58+
- 요소의 데이터는 free_data를 사용해서 메모리 할당을 해제해야 합니다.
59+
```
60+
void free_queue(t_queue *queue, void (*free_data)(void *));
61+
```
62+
63+
64+
[뒤로 가기](..)

queue/queue_array/queue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
typedef struct s_queue
2+
{
3+
unsigned int max_size;
4+
int last_index;
5+
void **data;
6+
} t_queue;

queue/queue_linked_list/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Queue(Linked List)
2+
3+
[뒤로 가기](..)
4+
5+
## exercise 00
6+
- linked list를 사용하여 queue를 구현 합니다.
7+
- 아래와 같은 queue.h를 사용 합니다.
8+
```
9+
typedef struct s_node
10+
{
11+
void *data;
12+
struct s_node *prev;
13+
struct s_node *next;
14+
} t_node;
15+
16+
typedef struct s_queue
17+
{
18+
unsigned int size;
19+
t_node **head;
20+
t_node **tail;
21+
} t_queue;
22+
```
23+
24+
### queue_init
25+
- t_queue형 struct를 반환 하는 함수를 작성하세요.
26+
- 반환되는 t_queue는 메모리 할당과 초기화를 거쳐야합니다.
27+
```
28+
t_queue *queue_init(void);
29+
```
30+
31+
### create_elem
32+
- t_node형 새로운 요소를 생성하는 함수를 작성하세요.
33+
```
34+
t_node *create_elem(void *data);
35+
```
36+
37+
### queue_push
38+
- queue의 가장 뒤에 data를 갖는 새로운 요소를 생성하는 함수를 작성하세요.
39+
- 성공하면 1, 실패하면 0을 반환 합니다.
40+
```
41+
int queue_push(t_queue *queue, void *data);
42+
```
43+
44+
### queue_size
45+
- queue에 있는 요소의 개수를 반환하는 함수를 작성하세요.
46+
```
47+
int queue_size(t_queue *queue);
48+
```
49+
50+
### queue_front
51+
- queue에서 가장 앞에 있는 요소를 반환하는 함수를 작성하세요.
52+
```
53+
t_node *queue_front(t_queue *queue);
54+
```
55+
56+
### queue_pop
57+
- queue에서 가장 앞에 있는 요소를 꺼내는 함수를 작성하세요.
58+
```
59+
t_node *queue_pop(t_queue *queue);
60+
```
61+
62+
### queue_clear
63+
- queue의 요소 전체를 삭제하는 함수를 작성하세요.
64+
- 요소의 데이터는 free_data를 사용해서 메모리 할당을 해제해야 합니다.
65+
```
66+
void queue_clear(t_queue *queue, void (*free_data)(void *));
67+
```
68+
69+
### free_queue
70+
- queue에 있는 요소 전체를 삭제하고 queue의 메모리 할당을 해제하는 함수를 작성하세요.
71+
- 요소의 데이터는 free_data를 사용해서 메모리 할당을 해제해야 합니다.
72+
```
73+
void free_queue(t_queue *queue, void (*free_data)(void *));
74+
```
75+
76+
77+
[뒤로 가기](..)

queue/queue_linked_list/stack.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
typedef struct s_node
2+
{
3+
void *data;
4+
struct s_node *next;
5+
} t_node;
6+
7+
typedef struct s_stack
8+
{
9+
unsigned int size;
10+
t_node **top;
11+
} t_stack;

0 commit comments

Comments
 (0)