diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 741f943..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d654349 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요. + // 기존 특성에 대한 설명을 보려면 가리킵니다. + // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요. + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/tasks 2.json b/.vscode/tasks 2.json new file mode 100644 index 0000000..ffb5da9 --- /dev/null +++ b/.vscode/tasks 2.json @@ -0,0 +1,29 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: clang 활성 파일 빌드", + "command": "/usr/bin/clang", + "args": [ + "-fcolor-diagnostics", + "-fansi-escape-codes", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "디버거에서 생성된 작업입니다." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ffb5da9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: clang 활성 파일 빌드", + "command": "/usr/bin/clang", + "args": [ + "-fcolor-diagnostics", + "-fansi-escape-codes", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "디버거에서 생성된 작업입니다." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array" new file mode 100755 index 0000000..2ca7f33 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array.c" new file mode 100644 index 0000000..688b95a --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/1Array.c" @@ -0,0 +1,19 @@ +#include + +int main(void) { + int i, length; + char str[50]; + + printf("문자열을 입력하세요: "); + gets(str); + printf("\n입력된 문자열은 \n"); + for(i = 0; str[i]; i++){ + printf("%c",str[i]); + length ++; + } + printf("\n입니다. \n"); + + printf("입력된 문자열의 길이 = %d \n", length); + + return 0; +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray" new file mode 100755 index 0000000..20ca578 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray.c" new file mode 100644 index 0000000..509abfb --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/2DeCharArray.c" @@ -0,0 +1,26 @@ +#include + +int main(void) { + int i,j,k; + char student[2][3][20]; + + for (i = 0; i < 2; i++){ + printf("\n 학생 %d의 이름 : ", i + 1); + gets(student[i][0]); + printf("\n 학생 %d의 학과 : ", i + 1); + gets(student[i][1]); + printf("\n 학생 %d의 학과 : ", i + 1); + gets(student[i][2]); + } + + for(i = 0; i < 2; i ++){ + printf("학생%d \n", i + 1); + for(j = 0; j < 3; j++){ + // printf(" %c \n", student[i][j][20]); + for (k = 0; student[i][j][k] != '\0'; k++) { + printf(" %c \n", student[i][j][k]); + } + } + } + return 0; +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array" new file mode 100755 index 0000000..9d62879 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array.c" new file mode 100644 index 0000000..8d7dce8 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/3Array.c" @@ -0,0 +1,25 @@ +#include + +int main(void) { + int i,j,k; + int array[2][3][4]; + + for(i = 0; i < 2; i++){ + for(j = 0; j < 3; j++){ + for(k =0; k < 4; k++){ + printf("array[%d][%d][%d] =", i, j, k); + scanf("%d",&array[i][j][k]); + } + } + } + + for(i = 0; i < 2; i++){ + for(j = 0; j < 3; j++){ + for(k =0; k < 4; k++){ + printf("array[%d][%d][%d] = %d \n", i, j, k, array[i][j][k]); + } + } + } + + return 0; +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1" new file mode 100755 index 0000000..de1ad79 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.c" new file mode 100644 index 0000000..5ef143c --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.c" @@ -0,0 +1,10 @@ +#include + +int main(void) { + int num = 10; + int *pnum = # + + printf("%d, %d \n", num, *pnum); + + return 0; +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Info.plist" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Info.plist" new file mode 100644 index 0000000..7cf3c20 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Info.plist" @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.pointer1 + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/DWARF/pointer1" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/DWARF/pointer1" new file mode 100644 index 0000000..e528728 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/DWARF/pointer1" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/Relocations/aarch64/pointer1.yml" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/Relocations/aarch64/pointer1.yml" new file mode 100644 index 0000000..2f96f80 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointer1.dSYM/Contents/Resources/Relocations/aarch64/pointer1.yml" @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: "/Users/hataeuk/Documents/Data_Structure_Assignment/2주차 실습/pointer1" +relocations: [] +... diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray" new file mode 100755 index 0000000..87adbcc Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.c" new file mode 100644 index 0000000..f7baf79 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.c" @@ -0,0 +1,9 @@ +#include + +int main(void) { + + char string[3][10] = {"Dreams", "come", "true!"}; + char *ptr[3] = {"Dreams", "come", "true!"}; + + return 0; +} \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Info.plist" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Info.plist" new file mode 100644 index 0000000..5636d53 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Info.plist" @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.pointerArray + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/DWARF/pointerArray" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/DWARF/pointerArray" new file mode 100644 index 0000000..a9fc0df Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/DWARF/pointerArray" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/Relocations/aarch64/pointerArray.yml" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/Relocations/aarch64/pointerArray.yml" new file mode 100644 index 0000000..26b651e --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/pointerArray.dSYM/Contents/Resources/Relocations/aarch64/pointerArray.yml" @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: "/Users/hataeuk/Documents/Data_Structure_Assignment/2주차 실습/pointerArray" +relocations: [] +... diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1" new file mode 100755 index 0000000..1b25c70 Binary files /dev/null and "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1" differ diff --git "a/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1.c" "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1.c" new file mode 100644 index 0000000..2e00f80 --- /dev/null +++ "b/2\354\243\274\354\260\250 \354\213\244\354\212\265/ponter_assginment1.c" @@ -0,0 +1,17 @@ +#include + +int main(void) { + int i; + char *ptr[4] = { {"Korea"}, {"Seoul"}, {"Mapo"}, {"152번지 2/3"} }; + for (i = 0; i <4; i++){ + printf("\n %s", ptr[i]); + } + printf("\n"); + ptr[2] = "Jongno"; + for (i = 0; i <4; i++){ + printf("\n %s", ptr[i]); + } + + return 0; + +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.c" new file mode 100644 index 0000000..2b2a714 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.c" @@ -0,0 +1,80 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include "InsertLinkedList.h" + +//공백 연결 리스트를 생성하는 연산 +linkedList_h* createLinkedList_h(void) { + linkedList_h* L; + L = (linkedList_h*)malloc(sizeof(linkedList_h)); + L -> head = NULL; + return L; +} + +//연결 리스트의 전체 메모리를 해제하는 연산 +void freeLinkedList_h(linkedList_h* L) { + listNode* p; + while (L -> head != NULL) { + p = L -> head; + L -> head = L -> head -> link; + free(p); + p = NULL; + } +} + +//연결 리스트를 순서대로 출력하는 연산 +void printList(linkedList_h* L){ + listNode *p; + printf("L = ("); + p = L -> head; + while ( p != NULL) { + printf("%s", p -> data); + p = p -> link; + if(p != NULL) printf(", "); + } + printf("\n"); +} + +// 첫번째 노드로 삽입하는 연산 +void insertFirstNode(linkedList_h * L, char* x){ + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); //삽입할 새 노드 할당 + strcpy(newNode -> data, x); //새 노드의 데이터 필드에 x 저장 + newNode -> link = L -> head; + L -> head = newNode; +} + +//노드를 pre 뒤에 삽입하는 연산 +void insertMiddleNode(linkedList_h* L, listNode *pre, char* x) { + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode -> data, x); + if (L -> head == NULL) { //공백 리스트인 경우 + newNode -> link = NULL; // 새 노드를 첫 번째이자 마지막 노드로 연결 + L -> head = newNode; + } + else if(pre == NULL) { //삽입 위치를 지정하는 포인터 pre가 NULL인 경우 + newNode -> link = L -> head; //새 노드를 첫 번째 노드로 삽입 + L -> head = newNode; + } + else { // 포인터 pre의 노드 뒤에 새 노드 연결 + newNode -> link = pre -> link; + pre -> link = newNode; + } +} + +void insertLastNode(linkedList_h* L,char* x) { + listNode* newNode; + listNode* temp; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode -> data, x); + newNode -> link = NULL; + if (L -> head == NULL) { //현재 리스트가 공백인 경우 + L -> head = newNode; + return; + } + temp = L -> head; + while(temp -> link != NULL) temp = temp -> link; // 현재 리스트의 마지막 노드를 찾음 + temp -> link = newNode; //새 노드를 마지막 노드(temp)의 다음 노드로 연결 +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.h" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.h" new file mode 100644 index 0000000..73f6be8 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/InsertLinkedList.h" @@ -0,0 +1,19 @@ +#pragma once + +//단순 연결 리스트의 노드 구조를 구조체로 정의 +typedef struct ListNode { + char data[4]; + struct ListNode* link; +} listNode; + +// 리스트 시작을 나타내는 head 노드를 구조체로 정의 +typedef struct { + listNode* head; +} linkedList_h; + +linkedList_h* createLinkedList_h(void); +void freeLinkedList_h(linkedList_h* L); +void printList(linkedList_h * L); +void insertFirstNode(linkedList_h * L, char* x); +void insertMiddleNode(linkedList_h * L, listNode * pre, char* x); +void insertLastNode(linkedList_h* L, char* x); \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1" new file mode 100755 index 0000000..4835269 Binary files /dev/null and "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1" differ diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1.c" new file mode 100644 index 0000000..a923318 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex4_1.c" @@ -0,0 +1,31 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include "InsertLinkedList.h" + +int main(void){ + linkedList_h* L; + L = createLinkedList_h(); + printf("(1) 공백 리스트 생성하기! \n"); + printList(L); + + printf("(2) 리스트에 [수] 노드 삽입하기! \n"); + insertFirstNode(L, "수"); + printList(L); + + printf("(3) 리스트 마지막에 [금] 삽입하기! \n"); + insertLastNode(L, "금"); + printList(L); + + printf("(4) 리스트 첫번째에 [월] 삽입하기! \n"); + insertFirstNode(L, "월"); + printList(L); + + printf("(5) 리스트 공간을 해제하여 공백 리스트로 만들기! \n"); + freeLinkedList_h(L); + printList(L); + + + getchar(); return 0; +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2" new file mode 100755 index 0000000..984117e Binary files /dev/null and "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2" differ diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2.c" new file mode 100644 index 0000000..c37b692 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex4_2.c" @@ -0,0 +1,38 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include "linkedList.h" + +int main(void){ + linkedList_h* L; + listNode* p; + L = createLinkedList_h(); + + printf("(1) 리스트에 [월], [수], [일] 노드 삽입하기! \n"); + insertLastNode(L, "월"); insertLastNode(L, "수"); insertLastNode(L, "일"); + printList(L); + + printf("\n (2) 리스트에서 [수] 노드 탐색하기! \n"); + p = searchNode(L, "수"); + if (p == NULL) printf("찾는 데이터가 없습니다. \n"); + else printf("[%s]를 찾았습니다. \n", p -> data); + + printf("\n (3) 리스트의 [수] 뒤에 [금] 노드 삽입하기! \n"); + insertMiddleNode(L, p, "금"); + printList(L); + + printf("\n (4) 리스트에서 [일] 노드 삭제하기! \n"); + p = searchNode(L, "일"); + deleteNode(L, p); + printList(L); + + printf("\n (5) 리스트 순서를 역순으로 바꾸기! \n"); + reverse(L); + printList(L); + + freeLinkedList_h(L); + getchar(); + + return 0; +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.c" new file mode 100644 index 0000000..e364fdc --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.c" @@ -0,0 +1,133 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include "linkedList.h" + +//공백 연결 리스트를 생성하는 연산 +linkedList_h* createLinkedList_h(void) { + linkedList_h* L; + L = (linkedList_h*)malloc(sizeof(linkedList_h)); + L -> head = NULL; + return L; +} + +//연결 리스트의 전체 메모리를 해제하는 연산 +void freeLinkedList_h(linkedList_h* L) { + listNode* p; + while (L -> head != NULL) { + p = L -> head; + L -> head = L -> head -> link; + free(p); + p = NULL; + } +} + +//연결 리스트를 순서대로 출력하는 연산 +void printList(linkedList_h* L){ + listNode *p; + printf("L = ("); + p = L -> head; + while ( p != NULL) { + printf("%s", p -> data); + p = p -> link; + if(p != NULL) printf(", "); + } + printf("\n"); +} + +// 첫번째 노드로 삽입하는 연산 +void insertFirstNode(linkedList_h * L, char* x){ + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); //삽입할 새 노드 할당 + strcpy(newNode -> data, x); //새 노드의 데이터 필드에 x 저장 + newNode -> link = L -> head; + L -> head = newNode; +} + +//노드를 pre 뒤에 삽입하는 연산 +void insertMiddleNode(linkedList_h* L, listNode *pre, char* x) { + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode -> data, x); + if (L -> head == NULL) { //공백 리스트인 경우 + newNode -> link = NULL; // 새 노드를 첫 번째이자 마지막 노드로 연결 + L -> head = newNode; + } + else if(pre == NULL) { //삽입 위치를 지정하는 포인터 pre가 NULL인 경우 + newNode -> link = L -> head; //새 노드를 첫 번째 노드로 삽입 + L -> head = newNode; + } + else { // 포인터 pre의 노드 뒤에 새 노드 연결 + newNode -> link = pre -> link; + pre -> link = newNode; + } +} + +void insertLastNode(linkedList_h* L,char* x) { + listNode* newNode; + listNode* temp; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode -> data, x); + newNode -> link = NULL; + if (L -> head == NULL) { //현재 리스트가 공백인 경우 + L -> head = newNode; + return; + } + temp = L -> head; + while(temp -> link != NULL) temp = temp -> link; // 현재 리스트의 마지막 노드를 찾음 + temp -> link = newNode; //새 노드를 마지막 노드(temp)의 다음 노드로 연결 +} + +//리스트에서 노드 p를 삭제하는 연산 +void deleteNode(linkedList_h* L, listNode* p) { + listNode* pre; + if(L -> head != NULL) return; //공백 리스트라면 삭제 연산 중단 + if(L -> head -> link == NULL) { + free(L -> head); //첫 번째 노드를 메모리에서 해제하고 + L -> head = NULL; + return; + } + else if (p == NULL) return; + else { + pre = L -> head; + while (pre -> link != p) { + pre = pre -> link; + } + pre -> link = p -> link; + free(p); + } +} + +//리스트에서 x노드를 탐색하는 연산 +listNode* searchNode(linkedList_h* L, char* x) { + listNode* temp; + temp = L -> head; + while (temp != NULL) { + if (strcmp(temp -> data, x) == 0) return temp; //탐색 성공 + else temp = temp -> link; + } + return temp; +} + +//리스트의 노드 순서를 역순으로 바꾸는 연산 +void reverse(linkedList_h* L) { + listNode* p; + listNode* q; + listNode* r; + + p = L -> head; //포인터 p를 첫 번째 노드에 설정 + q = NULL; + r = NULL; + + //리스트의 첫 번째 노드부터 링크를 따라 다음 노드로 이동하면서 + // 노드 간의 연결을 바꿈 + while (p != NULL) { + r = q; + q = p; + p = p -> link; + q -> link = r; + } + L -> head = q; + +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.h" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.h" new file mode 100644 index 0000000..2182a1b --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2652/linkedList.h" @@ -0,0 +1,22 @@ +#pragma once + +//단순 연결 리스트의 노드 구조를 구조체로 정의 +typedef struct ListNode { + char data[4]; + struct ListNode* link; +} listNode; + +// 리스트 시작을 나타내는 head 노드를 구조체로 정의 +typedef struct { + listNode* head; +} linkedList_h; + +linkedList_h* createLinkedList_h(void); +void freeLinkedList_h(linkedList_h* L); +void printList(linkedList_h * L); +void insertFirstNode(linkedList_h * L, char* x); +void insertMiddleNode(linkedList_h * L, listNode * pre, char* x); +void insertLastNode(linkedList_h* L, char* x); +void deleteNode(linkedList_h* L, listNode* p); +listNode* searchNode(linkedList_h* L, char* x); +void reverse(linkedList_h* L); diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.c" new file mode 100644 index 0000000..37f93c0 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.c" @@ -0,0 +1,91 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include "CircularLinkedList.h" + +linkedList_h* createLinkedList_h(void) { + linkedList_h* CL; + CL = (linkedList_h*)malloc(sizeof(linkedList_h)); + CL->head = NULL; + return CL; +} + +void printList(linkedList_h* CL) { + listNode* p; + printf(" CL = ("); + p = CL->head; + + if (p == NULL) { + printf(") \n"); return; + } + do { + printf("%s", p->data); + p = p->link; + if (p != CL->head) printf(", "); + } while (p != CL->head); + printf(") \n"); +} + +void insertFirstNode(linkedList_h* CL, char* x) { + listNode* newNode, * temp; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode->data, x); + if (CL->head == NULL) { + CL->head = newNode; + newNode->link = newNode; + } + else { + temp = CL->head; + while (temp->link != CL->head) + temp = temp->link; + newNode->link = temp->link; + temp->link = newNode; + CL->head = newNode; + } +} + +void insertMiddleNode(linkedList_h* CL, listNode* pre, char* x) { + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode->data, x); + if (CL->head == NULL) { + CL->head = newNode; + newNode->link = newNode; + } + else { + newNode->link = pre->link; + pre->link = newNode; + } +} + +void deleteNode(linkedList_h* CL, listNode* old) { + listNode* pre; + if (CL->head == NULL) return; + if (CL->head->link == CL->head) { + free(CL->head); + CL->head = NULL; + return; + } + else if (old == NULL) return; + else { + pre = CL->head; + while (pre->link != old) { + pre = pre->link; + } + pre->link = old->link; + if (old == CL->head) + CL->head = old->link; + free(old); + } +} + +listNode* searchNode(linkedList_h* CL, char* x) { + listNode* temp; + temp = CL->head; + if (temp == NULL) return NULL; + do { + if (strcmp(temp->data, x) == 0) return temp; + else temp = temp->link; + } while (temp != CL->head); + return NULL; +} diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.h" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.h" new file mode 100644 index 0000000..e19880f --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/CircularLinkedList.h" @@ -0,0 +1,16 @@ +#pragma once +typedef struct ListNode { + char data[4]; + struct ListNode* link; +} listNode; + +typedef struct { + listNode* head; +} linkedList_h; + +linkedList_h* createLinkedList_h(void); +void printList(linkedList_h* CL); +void insertFirstNode(linkedList_h* CL, char* x); +void insertMiddleNode(linkedList_h* CL, listNode* pre, char* x); +void deleteNode(linkedList_h* CL, listNode* old); +listNode* searchNode(linkedList_h* CL, char* x); diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/ex4_3.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/ex4_3.c" new file mode 100644 index 0000000..4353ebe --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2653/ex4_3.c" @@ -0,0 +1,27 @@ +#include "CircularLinkedList.h" + +int main(void) { + linkedList_h* CL; + listNode* p; + + CL = createLinkedList_h(); + printf("(1) Create Circular Linked List! \n"); + printList(CL); + + printf("\n(2) Insert First Node! \n"); + insertFirstNode(CL, "A"); + printList(CL); + + printf("\n(3) Insert Middle Node after First! \n"); + p = searchNode(CL, "A"); insertMiddleNode(CL, p, "B"); + printList(CL); + + printf("\n(4) Insert Middle Node after Second! \n"); + p = searchNode(CL, "B"); insertMiddleNode(CL, p, "C"); + printList(CL); + + printf("\n(5) Delete Node! \n"); + p = searchNode(CL, "A"); deleteNode(CL, p); + printList(CL); getchar(); + return 0; +} diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.c" new file mode 100644 index 0000000..1f4e802 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.c" @@ -0,0 +1,65 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include "DoubleLinkedList.h" + +linkedList_h* createLinkedList_h(void) { + linkedList_h* DL; + DL = (linkedList_h*)malloc(sizeof(linkedList_h)); + DL->head = NULL; + return DL; +} + + +void printList(linkedList_h* DL) { + listNode* p; + printf(" DL = ("); + p = DL->head; + + while (p != NULL) { + printf("%s", p->data); + p = p->rlink; + if (p != NULL) printf(", "); + } + printf(") \n"); +} + + +void insertNode(linkedList_h* DL, listNode* pre, char* x) { + listNode* newNode; + newNode = (listNode*)malloc(sizeof(listNode)); + strcpy(newNode->data, x); + if (DL->head == NULL) { + newNode->rlink = NULL; + newNode->llink = NULL; + DL->head = newNode; + } + else { + newNode->rlink = pre->rlink; + pre->rlink = newNode; + newNode->llink = pre; + if (newNode->rlink != NULL) + newNode->rlink->llink = newNode; + } +} + + +void deleteNode(linkedList_h* DL, listNode* old) { + if (DL->head == NULL) return; + else if (old == NULL) return; + else { + old->llink->rlink = old->rlink; + old->rlink->llink = old->llink; + free(old); + } +} + +listNode* searchNode(linkedList_h* DL, char* x) { + listNode* temp; + temp = DL->head; + while (temp != NULL) { + if (strcmp(temp->data, x) == 0) return temp; + else temp = temp->rlink; + } + return temp; +} \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.h" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.h" new file mode 100644 index 0000000..658f362 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/DoubleLinkedList.h" @@ -0,0 +1,17 @@ +#pragma once + +typedef struct ListNode { + struct ListNode* llink; + char data[4]; + struct ListNode* rlink; +} listNode; + +typedef struct { + listNode* head; +} linkedList_h; + +linkedList_h* createLinkedList_h(void); +void printList(linkedList_h* DL); +void insertNode(linkedList_h* DL, listNode* pre, char* x); +void deleteNode(linkedList_h* DL, listNode* old); +listNode* searchNode(linkedList_h* DL, char* x); \ No newline at end of file diff --git "a/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/ex4_4.c" "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/ex4_4.c" new file mode 100644 index 0000000..057bcc1 --- /dev/null +++ "b/4\354\243\274\354\260\250 \352\260\225\354\235\230\354\236\220\353\243\214 \354\213\244\354\212\265/\354\213\244\354\212\2654/ex4_4.c" @@ -0,0 +1,29 @@ +#include +#include "DoubleLinkedList.h" + +int main(void) { + linkedList_h* DL; + listNode* p; + + DL = createLinkedList_h(); + printf("(1) ���� ���� ����Ʈ �����ϱ�! \n"); + printList(DL); + + printf("\n(2) ���� ���� ����Ʈ�� [��] ��� �����ϱ�! \n"); + insertNode(DL, NULL, "��"); + printList(DL); + + printf("\n(3) ���� ���� ����Ʈ�� [��] ��� �ڿ� [��] ��� �����ϱ�! \n"); + p = searchNode(DL, "��"); insertNode(DL, p, "��"); + printList(DL); + + printf("\n(4) ���� ���� ����Ʈ�� [��] ��� �ڿ� [��] ��� �����ϱ�! \n"); + p = searchNode(DL, "��"); insertNode(DL, p, "��"); + printList(DL); + + printf("\n(5) ���� ���� ����Ʈ���� [��] ��� �����ϱ�! \n"); + p = searchNode(DL, "��"); deleteNode(DL, p); + printList(DL); + + getchar(); return 0; +} \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1" new file mode 100755 index 0000000..8c7c001 Binary files /dev/null and "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1" differ diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1.c" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1.c" new file mode 100644 index 0000000..36bc6b0 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/ex5_1.c" @@ -0,0 +1,72 @@ +#include +#include "stackS.h" +#include + +int top = -1; + +int isStackEmpty() { + if (top== -1) return 1; + else return 0; +} + +int isStackFull() { + if(top == STACK_SIZE -1) return 1; + else return 0; +} + +void push (element item) { + if (isStackFull()) { + printf("\n\n Stack is full! \n"); + return; + } + else stack[++top] = item; +} + +element pop() { + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return -0; + } + else return stack[top--]; +} + +element peek() { + if (isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + exit(1); + } + else return stack[top]; +} + +void printStack() { + int i; + printf("\n STACK [ "); + for (i = 0; i <= top; i++) { + printf("%d", stack[i]); + printf("] "); + } +} + +int main(void) { + element item; + printf("\n** 순차 스택 연산 **\n"); + printStack(); + push(1); printStack(); + push(2); printStack(); + push(3); printStack(); + + item = peek(); printStack(); + printf("peek => %d", item); + + item = pop(); printStack(); + printf("\n pop => %d", item); + + item = pop(); printStack(); + printf("\n pop => %d", item); + + item = pop(); printStack(); + printf("\n pop => %d", item); + + getchar(); return 0; + +} \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.c" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.c" new file mode 100644 index 0000000..f5b6a5a --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.c" @@ -0,0 +1,47 @@ +#include +#include "stackS.h" + +int top = -1; + +int isStackEmpty() { + if (top== -1) return 1; + else return 0; +} + +int isStackFull() { + if(top == STACK_SIZE -1) return 1; + else return 0; +} + +void push (element item) { + if (isStackFull()) { + printf("\n\n Stack is full! \n"); + return; + } + else stack[++top] = item; +} + +element pop() { + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return -0; + } + else return stack[top--]; +} + +element peek() { + if (isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + exit(1); + } + else return stack[top]; +} + +void printStack() { + int i; + printf("\n STACK [ "); + for (i = 0; i <= top; i++) { + printf("%d", stack[i]); + printf("] "); + } +} diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.h" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.h" new file mode 100644 index 0000000..fe5cd22 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2651/stackS.h" @@ -0,0 +1,12 @@ +#pragma once +#define STACK_SIZE 100 + +typedef int element; // 스택 원소(element)의 자료형을 int로 정의 +element stack[STACK_SIZE]; // 1차원 배열 스택 선언 + +int isStackEmpty(); +int isStackFull(); +void push(element item); +element pop(); +element peek(); +void printStack(); \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2" new file mode 100755 index 0000000..eb382a9 Binary files /dev/null and "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2" differ diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.c" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.c" new file mode 100644 index 0000000..250100a --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.c" @@ -0,0 +1,73 @@ +#include +#include "stackL.h" +#include + +int isStackEmpty() { + if (top== NULL) return 1; + else return 0; +} + +void push (element item) { + stackNode* temp = (stackNode*)malloc(sizeof(stackNode)); + temp->data = item; + temp->link = top; + top = temp; +} + +element pop(){ + element item; + stackNode* temp = top; + + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return 0; + } + else { + item = temp->data; + top = temp->link; + free(temp); + return item; + } +} + +element peek(){ + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return 0; + } + else return (top->data); +} + +void printStack() { + stackNode* p = top; + printf("\n STACK [ "); + while(p) { + printf("%d ", p->data); + p = p->link; + } + printf(" ] "); +} + +int main(void) { + element item; + printf("\n** 연결 스택 연산 **\n"); + printStack(); + push(1); printStack(); + push(2); printStack(); + push(3); printStack(); + + item = peek(); printStack(); + printf("peek => %d", item); + + item = pop(); printStack(); + printf("\n pop => %d", item); + + item = pop(); printStack(); + printf("\n pop => %d", item); + + item = pop(); printStack(); + printf("\n pop =>%d \n", item); + + getchar(); return 0; + +} \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Info.plist" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Info.plist" new file mode 100644 index 0000000..dae9684 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Info.plist" @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.ex5_2 + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/DWARF/ex5_2" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/DWARF/ex5_2" new file mode 100644 index 0000000..ff898e3 Binary files /dev/null and "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/DWARF/ex5_2" differ diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/Relocations/aarch64/ex5_2.yml" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/Relocations/aarch64/ex5_2.yml" new file mode 100644 index 0000000..45ca024 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/ex5_2.dSYM/Contents/Resources/Relocations/aarch64/ex5_2.yml" @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: "/Users/hataeuk/Documents/Data_Structure_Assignment/5주차 실습/실습2/ex5_2" +relocations: [] +... diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.c" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.c" new file mode 100644 index 0000000..67f74e9 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.c" @@ -0,0 +1,49 @@ +#include +#include "stackL.h" + +int isStackEmpty() { + if (top== NULL) return 1; + else return 0; +} + +void push (element item) { + stackNode* temp = (stackNode*)malloc(sizeof(stackNode)); + temp->data = item; + temp->link = top; + top = temp; +} + +element pop(){ + element item; + stackNode* temp = top; + + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return 0; + } + else { + item = temp->data; + top = temp->link; + free(temp); + return item; + } +} + +element peek(){ + if(isStackEmpty()) { + printf("\n\n Stack is empty! \n"); + return 0; + } + else return (top->data); +} + +void printStack() { + stackNode* p = top; + printf("\n STACK [ "); + while(p) { + printf("%d ", p->data); + printf("] "); + p = p->link; + } + printf("] "); +} \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.h" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.h" new file mode 100644 index 0000000..4ee2ea0 --- /dev/null +++ "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/stackL.h" @@ -0,0 +1,15 @@ +#pragma once +typedef int element; + +typedef struct stackNode { + element data; // int = elemnt + struct stackNode* link; +} stackNode; + +stackNode* top; + +int isStackEmpty(); +void push(element item); +element pop(); +element peek(); +void printStack(); \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/\354\212\244\355\201\254\353\246\260\354\203\267 2026-04-02 \354\230\244\354\240\204 11.15.50.png" "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/\354\212\244\355\201\254\353\246\260\354\203\267 2026-04-02 \354\230\244\354\240\204 11.15.50.png" new file mode 100644 index 0000000..170a258 Binary files /dev/null and "b/5\354\243\274\354\260\250 \354\213\244\354\212\265/\354\213\244\354\212\2652/\354\212\244\355\201\254\353\246\260\354\203\267 2026-04-02 \354\230\244\354\240\204 11.15.50.png" differ diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1" new file mode 100755 index 0000000..11cb296 Binary files /dev/null and "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1" differ diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.c" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.c" new file mode 100644 index 0000000..b2e98d8 --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.c" @@ -0,0 +1,77 @@ +#include +#include +#include "queue1.h" + +QueueType* createQueue() { + QueueType* Q = (QueueType*)malloc(sizeof(QueueType)); + Q->front = -1; + Q->rear = -1; + return Q; +} + +int isQueueEmpty(QueueType* Q) { +//true =1, false = 0 + if (Q->front == Q->rear) { + printf("큐가 비어있습니다.\n"); + return 1; + } + else return 0; +} + +int isQueueFull(QueueType* Q) { + if(Q->rear == Q_SIZE -1) { + printf("큐가 꽉 찼습니다.\n"); + return 1; + } + else return 0; +} + +void enQueue(QueueType* Q, element item) { + if (isQueueFull(Q)) return; + else { + Q->rear = Q->rear + 1; + Q->queue[Q->rear] = item; + } +} +element deQueue(QueueType* Q) { + if (isQueueEmpty(Q)) return 0; + else { + Q->front = Q->front +1; + return Q->queue[Q->front]; + } +} +element peek(QueueType* Q) { + if (isQueueEmpty(Q)) return 0; + else { + return Q->queue[Q->front + 1]; + } +} + +void printQ(QueueType* Q) { + printf("Queue: [ "); + for (int i = Q->front + 1; i <= Q->rear; i++) { + printf("%c ", Q->queue[i]); + } + printf("]\n"); +} + +int main(void){ + printf("***** 순차 큐 연산 *****\n"); + QueueType* Q1 = createQueue(); + element data; + printf("삽입 A>>"); enQueue(Q1, 'A'); printQ(Q1); + printf("삽입 B>>"); enQueue(Q1, 'B'); printQ(Q1); + printf("삽입 C>>"); enQueue(Q1, 'C'); printQ(Q1); + data = peek(Q1); printf("peek item: %c\n", data); + printf("\n삭제 >>"); data = deQueue(Q1); printQ(Q1); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deQueue(Q1); printQ(Q1); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deQueue(Q1); printQ(Q1); + printf("\t삭제 데이터 : %c", data); + + printf("\n 삽입 D>>"); enQueue(Q1, 'D'); printQ(Q1); + printf("\n 삽입 E>>"); enQueue(Q1, 'E'); printQ(Q1); + + return 0; +} diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Info.plist" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Info.plist" new file mode 100644 index 0000000..71e68ed --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Info.plist" @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.queue1 + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/DWARF/queue1" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/DWARF/queue1" new file mode 100644 index 0000000..50e72c8 Binary files /dev/null and "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/DWARF/queue1" differ diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/Relocations/aarch64/queue1.yml" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/Relocations/aarch64/queue1.yml" new file mode 100644 index 0000000..efae92a --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.dSYM/Contents/Resources/Relocations/aarch64/queue1.yml" @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: "/Users/hataeuk/Documents/Data_Structure_Assignment/6주차 실습/queue1" +relocations: [] +... diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.h" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.h" new file mode 100644 index 0000000..7a542e6 --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue1.h" @@ -0,0 +1,16 @@ +#pragma once +#define Q_SIZE 4 +typedef char element; + +typedef struct { + element queue[Q_SIZE]; + int front, rear; +} QueueType; + +QueueType* createQueue(); +int isQueueEmpty(QueueType* Q); +int isQueueFull(QueueType* Q); +void enQueue(QueueType* Q, element item); +element deQueue(QueueType* Q); +element peek(QueueType* Q); +void printQ(QueueType* Q); diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2" new file mode 100755 index 0000000..72d0e7f Binary files /dev/null and "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2" differ diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.c" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.c" new file mode 100644 index 0000000..7415ec2 --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.c" @@ -0,0 +1,81 @@ +#include +#include +#include "queue2.h" + +QueueType* createCQueue() { + QueueType* cQ; + cQ = (QueueType*)malloc(sizeof(QueueType)); + cQ->front = 0; + cQ->rear = 0; + return cQ; +} + +int isCQueueFull(QueueType *cQ){ + if(((cQ->rear +1) % cQ_SIZE) == cQ -> front) { + printf("큐가 꽉 찼습니다.\n"); + return 1; + } + else return 0; + } + +int isCQueueEmpty(QueueType *cQ){ + if(cQ->front == cQ->rear) { + printf("큐가 비어있습니다.\n"); + return 1; + } + else return 0; +} + +void enCQueue(QueueType *cQ, element item){ + if(isCQueueFull(cQ)) return; + else { + cQ->rear = (cQ->rear + 1) % cQ_SIZE; + cQ->queue[cQ->rear] = item; + } +} + +element deCQueue(QueueType *cQ) { + if(isCQueueEmpty(cQ)) return 0; + else { + cQ->front = (cQ->front +1) % cQ_SIZE; + return cQ->queue[cQ->front]; + } +} + +element peekCQ(QueueType* cQ){ + if(isCQueueEmpty(cQ)) return 0; + else return cQ->queue[(cQ->front + 1) % cQ_SIZE]; +} + +void printCQ(QueueType *cQ) { + int i, first, last; + first = (cQ->front + 1) % cQ_SIZE; + last = (cQ->rear + 1) % cQ_SIZE; + printf("Circular Queue: ["); + i = first; + while (i != last) { + printf("%3c", cQ->queue[i]); + i = (i +1 ) % cQ_SIZE; + } + printf(" ] "); +} + +int main(void) { + QueueType *cQ = createCQueue(); + element data; + printf("\n ***** 원형 큐 연산 ***** \n"); + printf("삽입 A>>"); enCQueue(cQ, 'A'); printCQ(cQ); + printf("삽입 B>>"); enCQueue(cQ, 'B'); printCQ(cQ); + printf("삽입 C>>"); enCQueue(cQ, 'C'); printCQ(cQ); + data = peekCQ(cQ); printf("peek item: %c\n", data); + printf("\n삭제 >>"); data = deCQueue(cQ); printCQ(cQ); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deCQueue(cQ); printCQ(cQ); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deCQueue(cQ); printCQ(cQ); + printf("\t삭제 데이터 : %c", data); + + printf("\n 삽입 D>>"); enCQueue(cQ, 'D'); printCQ(cQ); + printf("\n 삽입 E>>"); enCQueue(cQ, 'E'); printCQ(cQ); + getchar(); return 0; +} \ No newline at end of file diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.h" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.h" new file mode 100644 index 0000000..be6aa3a --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue2.h" @@ -0,0 +1,17 @@ +#pragma once +#define cQ_SIZE 4 + +typedef char element; + +typedef struct { + element queue[cQ_SIZE]; + int front, rear; +} QueueType; + +QueueType* createQueue(); +int isQueueEmpty(QueueType* cQ); +int isQueueFull(QueueType* cQ); +void enQueue(QueueType* cQ, element item); +element deQueue(QueueType* cQ); +element peekcQ(QueueType* cQ); +void printCQ(QueueType* cQ); \ No newline at end of file diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.c" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.c" new file mode 100644 index 0000000..bd1987a --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.c" @@ -0,0 +1,86 @@ +#include +#include +#include "queue3.h" + +LQueueType* createLinkedQueue(void) { + LQueueType *LQ; + LQ = (LQueueType*)malloc(sizeof(LQueueType)); + LQ->front = NULL; + LQ->rear = NULL; + return LQ; +} + +int isLQEmpty(LQueueType* LQ) { + if(LQ->front == NULL){ + printf(" Linked Queue is empty! "); + return 1; + } + else return 0; +} + +void enLQueue(LQueueType *LQ, element item) { + QNode* newNode = (QNode*)malloc(sizeof(QNode)); + newNode->data = item; + newNode->link = NULL; + if(LQ->front == NULL) { //현재 연결 큐가 공백 상태인 경우 + LQ->front = newNode; + LQ->rear = newNode; + } + else { // 현재 연결 큐가 공백 상태가 아닌 경우 + LQ->rear->link = newNode; + LQ->rear = newNode; + } +} + +element deLQueue(LQueueType* LQ){ + QNode * old = LQ->front; + element item; + if(isLQEmpty(LQ)) return ; + else { + item = old -> data; + LQ->front = LQ->front->link; + if (LQ->front = NULL) + LQ->rear = NULL; + free(old); + return item; + } +} + +element peekLQ(LQueueType* LQ){ + element item; + if (isLQEmpty(LQ)) return; + else { + item = LQ->front->data; + return item; + } +} + +void printLQ(LQueueType* LQ) { + QNode* temp = LQ->front; + printf(" Linked Queue: ["); + while (temp) { + printf("%3c", temp->data); + temp = temp -> link; + } + printf(" ] "); +} + +int main(void) { + LQueueType *LQ = createLQueue(); + element data; + printf("\n ***** 연결 큐 연산 ***** \n"); + printf("삽입 A>>"); enLQueue(LQ, 'A'); printLQ(LQ); + printf("삽입 B>>"); enLQueue(LQ, 'B'); printLQ(LQ); + printf("삽입 C>>"); enLQueue(LQ, 'C'); printLQ(LQ); + data = peekLQ(LQ); printf("peek item: %c\n", data); + printf("\n삭제 >>"); data = deLQueue(LQ); printLQ(LQ); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deLQueue(LQ); printLQ(LQ); + printf("\t삭제 데이터 : %c", data); + printf("\n삭제 >>"); data = deLQueue(LQ); printLQ(LQ); + printf("\t삭제 데이터 : %c", data); + + printf("\n 삽입 D>>"); enLQueue(LQ, 'D'); printLQ(LQ); + printf("\n 삽입 E>>"); enLQueue(LQ, 'E'); printLQ(LQ); + getchar(); return 0; +} \ No newline at end of file diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.h" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.h" new file mode 100644 index 0000000..ebb437c --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue3.h" @@ -0,0 +1,20 @@ +#pragma once +typedef char element; + +typedef struct QNode { + element data; + struct QNode* link; +} QNode; + +typedef struct { + QNode* front, * rear; +} LQueueType; + +LQueueType* createLinkedQueue(void); +int isLQEmpty(LQueueType* LQ); +void enLQueue(LQueueType* LQ, element item); +element deLQueue(LQueueType* LQ); +element peekLQ(LQueueType* LQ); +void printLQ(LQueueType* LQ); + + diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4" new file mode 100755 index 0000000..cb65e0e Binary files /dev/null and "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4" differ diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.c" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.c" new file mode 100644 index 0000000..fcd8009 --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.c" @@ -0,0 +1,148 @@ +#include +#include +#include "queue4.h" + +DQueType* createDQue() { + DQueType* DQ; + DQ = (DQueType*)malloc(sizeof(DQueType)); + DQ->front = NULL; + DQ->rear = NULL; + return DQ; +} + +int isDeQEmpty(DQueType* DQ) { + if (DQ->front == NULL) return 1; + else return 0; +} + +void insertFront(DQueType* DQ, element item) { + DQNode* newNode = (DQNode*)malloc(sizeof(DQNode)); + newNode-> data = item; + if (isDeQEmpty(DQ)) { + DQ->front = newNode; + DQ->rear = newNode; + newNode->rlink = NULL; + newNode->llink = NULL; + } + else { + DQ->front->llink = newNode; + newNode->rlink = DQ->front; + newNode->llink = NULL; + DQ->front = newNode; + } +} + + +void insertRear(DQueType* DQ, element item) { + DQNode* newNode = (DQNode*)malloc(sizeof(DQNode)); + newNode->data = item; + if (isDeQEmpty(DQ)) { + DQ->front = newNode; + DQ->rear = newNode; + newNode->rlink = NULL; + newNode->llink = NULL; + } + else { + DQ->rear->rlink = newNode; + newNode->rlink = NULL; + newNode->llink = DQ->rear; + DQ->rear = newNode; + } +} + +element deleteFront(DQueType* DQ) { + DQNode* old = DQ->front; + element item; + if (isDeQEmpty(DQ)) { + printf("\n Linked deQue is empty! \n"); return '\0'; + } + else { + item = old->data; + if (DQ->front->rlink == NULL) { + DQ->front = NULL; + DQ->rear = NULL; + } + else { + DQ->front = DQ->front->rlink; + DQ->front->llink = NULL; + } + free(old); + return item; + } +} + +element deleteRear(DQueType* DQ) { + DQNode* old = DQ->rear; + element item; + if (isDeQEmpty(DQ)) { + printf("\n Linked deQue is empty! \n"); return '\0'; + } + else { + item = old->data; + if (DQ->rear->llink == NULL) { + DQ->front = NULL; + DQ->rear = NULL; + } + else { + DQ->rear = DQ->rear->llink; + DQ->rear->rlink = NULL; + } + free(old); + return item; + } +} + +element peekFront(DQueType* DQ) { + element item; + if (isDeQEmpty(DQ)) { + printf("\n Linked deQue is empty! \n"); return '\0'; + } + else { + item = DQ->front->data; + return item; + } +} + +element peekRear(DQueType* DQ) { + element item; + if (isDeQEmpty(DQ)) { + printf("\n Linked deQue is empty! \n"); return '\0'; + } + else { + item = DQ->rear->data; + return item; + } +} + +void printDQ(DQueType* DQ) { + DQNode* temp = DQ->front; + printf("DeQue : ["); + while (temp) { + printf("%3c", temp->data); + temp = temp->rlink; + } + printf(" ] "); +} + + +int main(void) +{ + DQueType* DQ1 = createDQue(); // ��ũ ���� + element data; + printf("\n ***** 데크 ***** \n"); + printf("\n front 삽입 A>> "); insertFront(DQ1, 'A'); printDQ(DQ1); + printf("\n front 삭제 B>> "); insertFront(DQ1, 'B'); printDQ(DQ1); + printf("\n rear 삽입 C>> "); insertRear(DQ1, 'C'); printDQ(DQ1); + printf("\n front 삭제 >> "); data = deleteFront(DQ1); printDQ(DQ1); + printf("\t삭제 데이터: %c", data); + printf("\n rear 삭제 >> "); data = deleteRear(DQ1); printDQ(DQ1); + printf("\t\t삭제 데이터: %c", data); + printf("\n rear 삽입 D>> "); insertRear(DQ1, 'D'); printDQ(DQ1); + printf("\n front 삽입 E>> "); insertFront(DQ1, 'E'); printDQ(DQ1); + printf("\n front 삽입 F>> "); insertFront(DQ1, 'F'); printDQ(DQ1); + + data = peekFront(DQ1); printf("\n peek Front item : %c \n", data); + data = peekRear(DQ1); printf(" peek Rear item : %c \n", data); + + getchar(); return 0; +} \ No newline at end of file diff --git "a/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.h" "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.h" new file mode 100644 index 0000000..ff5126e --- /dev/null +++ "b/6\354\243\274\354\260\250 \354\213\244\354\212\265/queue4.h" @@ -0,0 +1,22 @@ +#pragma once +typedef char element; + +typedef struct DQNode { + element data; + struct DQNode* llink; + struct DQNode* rlink; +} DQNode; + +typedef struct { + DQNode* front, * rear; +} DQueType; + +DQueType* createDQue(); +int isDeQEmpty(DQueType* DQ); +void insertFront(DQueType* DQ, element item); +void insertRear(DQueType* DQ, element item); +element deleteFront(DQueType* DQ); +element deleteRear(DQueType* DQ); +element peekFront(DQueType* DQ); +element peekRear(DQueType* DQ); +void printDQ(DQueType* DQ); \ No newline at end of file diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/TraversalBT.h" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/TraversalBT.h" new file mode 100644 index 0000000..2e630fc --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/TraversalBT.h" @@ -0,0 +1,13 @@ +#pragma once +typedef char element; + +typedef struct treeNode { + element data; + struct treeNode* left; + struct treeNode* right; +} treeNode; + +treeNode* makeRootNode(element data, treeNode* leftNode, treeNode* rightNode); +void preorder(treeNode* root); +void inorder(treeNode* root); +void postorder(treeNode* root); diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1" new file mode 100755 index 0000000..e814a04 Binary files /dev/null and "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1" differ diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.c" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.c" new file mode 100644 index 0000000..e31cd85 --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.c" @@ -0,0 +1,57 @@ +#include +#include +#include "TraversalBT.h" + +treeNode* makeRootNode(element data, treeNode* leftNode, treeNode* rightNode) { + treeNode* root = (treeNode*)malloc(sizeof(treeNode)); + root->data = data; + root->left = leftNode; + root->right = rightNode; + return root; +} + +void preorder(treeNode* root) { + if (root) { + printf("%c", root->data); + preorder(root->left); + preorder(root->right); + } +} + +void inorder(treeNode* root) { + if (root) { + inorder(root->left); + printf("%c", root->data); + inorder(root->right); + } +} + +void postorder(treeNode* root) { + if (root) { + postorder(root->left); + postorder(root->right); + printf("%c", root->data); + } +} + +int main(void) { + //(A+B-C/D) 수식 이진 트리 만들기 + treeNode* n7 = makeRootNode('D', NULL, NULL); + treeNode* n6 = makeRootNode('C', NULL, NULL); + treeNode* n5 = makeRootNode('B', NULL, NULL); + treeNode* n4 = makeRootNode('A', NULL, NULL); + treeNode* n3 = makeRootNode('/', n6, n7); + treeNode* n2 = makeRootNode('*', n4, n5); + treeNode* n1 = makeRootNode('-', n2, n3); + + printf("\n preorder : "); + preorder(n1); + + printf("\n inorder : "); + inorder(n1); + + printf("\n postorder : "); + postorder(n1); + + getchar(); return 0; +} \ No newline at end of file diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Info.plist" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Info.plist" new file mode 100644 index 0000000..14502c5 --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Info.plist" @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.ex7_1 + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/DWARF/ex7_1" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/DWARF/ex7_1" new file mode 100644 index 0000000..106d04f Binary files /dev/null and "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/DWARF/ex7_1" differ diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/Relocations/aarch64/ex7_1.yml" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/Relocations/aarch64/ex7_1.yml" new file mode 100644 index 0000000..7bb97d9 --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_1.dSYM/Contents/Resources/Relocations/aarch64/ex7_1.yml" @@ -0,0 +1,5 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: "/Users/hataeuk/Documents/Data_Structure_Assignment/7주차 실습/ex7_1" +relocations: [] +... diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2" new file mode 100755 index 0000000..5790423 Binary files /dev/null and "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2" differ diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2.c" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2.c" new file mode 100644 index 0000000..df4a214 --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/ex7_2.c" @@ -0,0 +1,43 @@ +#include +#include +#include "folderSize.h" + +treeNode* makeRootNode(int size, treeNode* leftNode, treeNode* rightNode) { + treeNode* root = (treeNode*)malloc(sizeof(treeNode)); + root->size = size; + root->left = leftNode; + root->right = rightNode; + return root; +} + +int postorder_FolderSize(treeNode* root) { + if (root) { + postorder_FolderSize(root->left); + postorder_FolderSize(root->right); + FolderSize += root->size; + } + return FolderSize; +} + +int main(void) { + treeNode* F11 = makeRootNode(120, NULL, NULL); + treeNode* F10 = makeRootNode(55, NULL, NULL); + treeNode* F9 = makeRootNode(100, NULL, NULL); + treeNode* F8 = makeRootNode(200, NULL, NULL); + treeNode* F7 = makeRootNode(68, F10, F11); + treeNode* F6 = makeRootNode(40, NULL, NULL); + treeNode* F5 = makeRootNode(15, NULL, NULL); + treeNode* F4 = makeRootNode(2, F8, F9); + treeNode* F3 = makeRootNode(10, F6, F7); + treeNode* F2 = makeRootNode(0, F4, F5); + treeNode* F1 = makeRootNode(0, F2, F3); + + FolderSize = 0; + printf("\n\n C: \\의 용량 : %d M \n", postorder_FolderSize(F2)); + FolderSize = 0; + printf("\n\n D: \\의 용량 : %d M \n", postorder_FolderSize(F3)); + FolderSize = 0; + printf("\n 내 컴퓨터의 전체 용량: %d M \n", postorder_FolderSize(F1)); + + getchar(); return 0; +} \ No newline at end of file diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/folderSize.h" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/folderSize.h" new file mode 100644 index 0000000..cb80e1f --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/folderSize.h" @@ -0,0 +1,10 @@ +#pragma once +int FolderSize; +typedef struct treeNode { + int size; + struct treeNode* left; + struct treeNode* right; +} treeNode; + +treeNode* makeRootNode(int size, treeNode* leftNode, treeNode* rightNode); +int postorder_FolderSize(treeNode* root); \ No newline at end of file diff --git "a/7\354\243\274\354\260\250 \354\213\244\354\212\265/tempCodeRunnerFile.c" "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/tempCodeRunnerFile.c" new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ "b/7\354\243\274\354\260\250 \354\213\244\354\212\265/tempCodeRunnerFile.c" @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git "a/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.c" "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.c" new file mode 100644 index 0000000..4f12d38 --- /dev/null +++ "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.c" @@ -0,0 +1,37 @@ +#include +#include +#include "adjMatrix.h" + +void createGraph(graphType* g) { + int i, j; + g->n = 0; + for (i = 0; i < MAX_VERTEX; i++) { + for (j = 0; j < MAX_VERTEX; j++) + g->adjMatrix[i][j] = 0; + } +} + +void insertVertex(graphType* g, int v) { + if (((g->n) + 1) > MAX_VERTEX) { + printf("\n 그래프 정점의 개수를 초과하였습니다!"); + return; + } + g->n++; +} + +void insertEdge(graphType* g, int u, int v) { + if (u >= g->n || v >= g->n) { + printf("\n 그래프에 없는 정점입니다!"); + return; + } + g->adjMatrix[u][v] = 1; +} + +void print_adjMatrix(graphType* g) { + int i, j; + for (i = 0; i < (g->n); i++) { + printf("\n\t\t"); + for (j = 0; j < (g->n); j++) + printf("%2d", g->adjMatrix[i][j]); + } +} \ No newline at end of file diff --git "a/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.h" "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.h" new file mode 100644 index 0000000..a88a41b --- /dev/null +++ "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/adjMatrix.h" @@ -0,0 +1,13 @@ +#pragma once +#define MAX_VERTEX 30 + + +typedef struct graphType { + int n; + int adjMatrix[MAX_VERTEX][MAX_VERTEX]; +} graphType; + +void createGraph(graphType* g); +void insertVertex(graphType* g, int v); +void insertEdge(graphType* g, int u, int v); +void print_adjMatrix(graphType* g); \ No newline at end of file diff --git "a/8\354\243\274\354\260\250 \354\213\244\354\212\265/ex8_1.c" "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/ex8_1.c" new file mode 100644 index 0000000..3d3c57c --- /dev/null +++ "b/8\354\243\274\354\260\250 \354\213\244\354\212\265/ex8_1.c" @@ -0,0 +1,66 @@ +#include +#include "adjMatrix.h" + +int main(void) { + int i; + graphType* G1 = (graphType*)malloc(sizeof(graphType)); + graphType* G2 = (graphType*)malloc(sizeof(graphType)); + graphType* G3 = (graphType*)malloc(sizeof(graphType)); + graphType* G4 = (graphType*)malloc(sizeof(graphType)); + + + createGraph(G1); + for (i = 0; i < 4; i++) + insertVertex(G1, i); + insertEdge(G1, 0, 3); + insertEdge(G1, 0, 1); + insertEdge(G1, 1, 3); + insertEdge(G1, 1, 2); + insertEdge(G1, 1, 0); + insertEdge(G1, 2, 3); + insertEdge(G1, 2, 1); + insertEdge(G1, 3, 2); + insertEdge(G1, 3, 1); + insertEdge(G1, 3, 0); + + createGraph(G2); + for (i = 0; i < 3; i++) + insertVertex(G2, i); + insertEdge(G2, 0, 2); + insertEdge(G2, 0, 1); + insertEdge(G2, 1, 2); + insertEdge(G2, 1, 0); + insertEdge(G2, 2, 1); + insertEdge(G2, 2, 0); + + createGraph(G3); + for (i = 0; i < 4; i++) + insertVertex(G3, i); + insertEdge(G3, 0, 3); + insertEdge(G3, 0, 1); + insertEdge(G3, 1, 3); + insertEdge(G3, 1, 2); + insertEdge(G3, 2, 3); + + createGraph(G4); + for (i = 0; i < 3; i++) + insertVertex(G4, i); + insertEdge(G4, 0, 2); + insertEdge(G4, 0, 1); + insertEdge(G4, 1, 2); + insertEdge(G4, 1, 0); + + printf("\n G1의 인접 행렬"); + print_adjMatrix(G1); + + printf("\n\n G2의 인접 행렬"); + print_adjMatrix(G2); + + printf("\n\n G3의 인접 행률"); + print_adjMatrix(G3); + + printf("\n\n G4의 인접 행렬"); + print_adjMatrix(G4); + + getchar(); return 0; +} \ No newline at end of file