Skip to content

Commit 64e11fd

Browse files
add Makefile.
1 parent e0aa595 commit 64e11fd

File tree

4 files changed

+97
-85
lines changed

4 files changed

+97
-85
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
FROM --platform=linux/arm64 debian:bullseye-slim
22

3-
# prepare
4-
RUN mkdir software
5-
63
# basic
74
RUN apt-get update \
85
&& apt-get install -y file curl vim

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"customizations": {
1010
"vscode": {
1111
"extensions": [
12-
"ms-vscode.cpptools"
12+
"ms-vscode.cpptools",
13+
"ms-vscode.makefile-tools"
1314
],
1415
"settings": {
1516
"editor.formatOnType": false

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
target:
2+
gcc -g main.c -o main
3+
4+
ck:
5+
valgrind --leak-check=full ./main
6+
7+
clean:
8+
rm -rf main

main.c

Lines changed: 87 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
// 10. delete last kth
1515
// 11. find middle node
1616

17+
// 12. remove =k elements
18+
// 13. rotate right
19+
// 14. get intersection
20+
// 15. check palinkdrome 12321
21+
1722
typedef struct SinglyLinkedNode {
1823
int data;
1924
struct SinglyLinkedNode *next;
@@ -63,6 +68,29 @@ void print_linked_list(SinglyLinkedNode *head) {
6368
}
6469
}
6570

71+
void test_create_print_free() {
72+
SinglyLinkedNode *head = NULL;
73+
append_node(&head, 1);
74+
append_node(&head, 2);
75+
append_node(&head, 3);
76+
append_node(&head, 4);
77+
78+
print_linked_list(head);
79+
80+
free_linked_list(head);
81+
}
82+
83+
void test_insert() {
84+
SinglyLinkedNode *head = NULL;
85+
insert_node(&head, 3);
86+
insert_node(&head, 2);
87+
insert_node(&head, 1);
88+
89+
print_linked_list(head);
90+
91+
free_linked_list(head);
92+
}
93+
6694
void reverse(SinglyLinkedNode **head_ref) {
6795
SinglyLinkedNode *current = *head_ref;
6896
SinglyLinkedNode *prev_node = NULL;
@@ -77,6 +105,20 @@ void reverse(SinglyLinkedNode **head_ref) {
77105
}
78106
}
79107

108+
void test_reverse() {
109+
SinglyLinkedNode *head = NULL;
110+
append_node(&head, 1);
111+
append_node(&head, 2);
112+
append_node(&head, 3);
113+
print_linked_list(head);
114+
115+
printf("---\n");
116+
reverse(&head);
117+
print_linked_list(head);
118+
119+
free_linked_list(head);
120+
}
121+
80122
int check_circle(SinglyLinkedNode *head) {
81123
SinglyLinkedNode *slow, *fast;
82124
slow = fast = head;
@@ -90,6 +132,21 @@ int check_circle(SinglyLinkedNode *head) {
90132
return 0;
91133
}
92134

135+
void test_circle() {
136+
SinglyLinkedNode *head = NULL;
137+
append_node(&head, 1);
138+
append_node(&head, 2);
139+
append_node(&head, 3);
140+
append_node(&head, 4);
141+
142+
head->next->next->next->next = head;
143+
144+
int has_circle = check_circle(head);
145+
printf("has circle = %d\n", has_circle);
146+
147+
free_linked_list(head);
148+
}
149+
93150
SinglyLinkedNode *find_middle_node(SinglyLinkedNode *head) {
94151
SinglyLinkedNode *slow, *fast;
95152
slow = fast = head;
@@ -100,6 +157,20 @@ SinglyLinkedNode *find_middle_node(SinglyLinkedNode *head) {
100157
return slow;
101158
}
102159

160+
void test_middle_node() {
161+
SinglyLinkedNode *head = NULL;
162+
append_node(&head, 1);
163+
append_node(&head, 2);
164+
append_node(&head, 3);
165+
append_node(&head, 4);
166+
append_node(&head, 5);
167+
168+
SinglyLinkedNode *middle_node = find_middle_node(head);
169+
printf("middle node value = %d\n", middle_node->data);
170+
171+
free_linked_list(head);
172+
}
173+
103174
void delete_last_kth(SinglyLinkedNode **head_ref, int k) {
104175
// 1. fast move k step
105176
SinglyLinkedNode *fast = *head_ref;
@@ -127,6 +198,22 @@ void delete_last_kth(SinglyLinkedNode **head_ref, int k) {
127198
free(slow);
128199
}
129200

201+
void test_delete_last_kth() {
202+
SinglyLinkedNode *head = NULL;
203+
append_node(&head, 1);
204+
append_node(&head, 2);
205+
append_node(&head, 3);
206+
append_node(&head, 4);
207+
append_node(&head, 5);
208+
print_linked_list(head);
209+
210+
delete_last_kth(&head, 2);
211+
print_linked_list(head);
212+
213+
free_linked_list(head);
214+
}
215+
216+
130217
// 1 3 5 | 2 4 6 -> 3 5 | 2 4 6
131218
void move_node(SinglyLinkedNode **dest_ref, SinglyLinkedNode **src_head_ref) {
132219
SinglyLinkedNode *new_node = *src_head_ref;
@@ -159,87 +246,6 @@ SinglyLinkedNode *merge_sorted_linked_list(SinglyLinkedNode *a , SinglyLinkedNod
159246
return result.next;
160247
}
161248

162-
void test_create_print_free() {
163-
SinglyLinkedNode *head = NULL;
164-
append_node(&head, 1);
165-
append_node(&head, 2);
166-
append_node(&head, 3);
167-
append_node(&head, 4);
168-
169-
print_linked_list(head);
170-
171-
free_linked_list(head);
172-
}
173-
174-
void test_insert() {
175-
SinglyLinkedNode *head = NULL;
176-
insert_node(&head, 3);
177-
insert_node(&head, 2);
178-
insert_node(&head, 1);
179-
180-
print_linked_list(head);
181-
182-
free_linked_list(head);
183-
}
184-
185-
void test_reverse() {
186-
SinglyLinkedNode *head = NULL;
187-
append_node(&head, 1);
188-
append_node(&head, 2);
189-
append_node(&head, 3);
190-
print_linked_list(head);
191-
192-
printf("---\n");
193-
reverse(&head);
194-
print_linked_list(head);
195-
196-
free_linked_list(head);
197-
}
198-
199-
void test_circle() {
200-
SinglyLinkedNode *head = NULL;
201-
append_node(&head, 1);
202-
append_node(&head, 2);
203-
append_node(&head, 3);
204-
append_node(&head, 4);
205-
206-
head->next->next->next->next = head;
207-
208-
int has_circle = check_circle(head);
209-
printf("has circle = %d\n", has_circle);
210-
211-
free_linked_list(head);
212-
}
213-
214-
void test_middle_node() {
215-
SinglyLinkedNode *head = NULL;
216-
append_node(&head, 1);
217-
append_node(&head, 2);
218-
append_node(&head, 3);
219-
append_node(&head, 4);
220-
append_node(&head, 5);
221-
222-
SinglyLinkedNode *middle_node = find_middle_node(head);
223-
printf("middle node value = %d\n", middle_node->data);
224-
225-
free_linked_list(head);
226-
}
227-
228-
void test_delete_last_kth() {
229-
SinglyLinkedNode *head = NULL;
230-
append_node(&head, 1);
231-
append_node(&head, 2);
232-
append_node(&head, 3);
233-
append_node(&head, 4);
234-
append_node(&head, 5);
235-
print_linked_list(head);
236-
237-
delete_last_kth(&head, 2);
238-
print_linked_list(head);
239-
240-
free_linked_list(head);
241-
}
242-
243249
void test_merge_sorted_linked_list() {
244250
SinglyLinkedNode *a = NULL;
245251
append_node(&a, 1);

0 commit comments

Comments
 (0)