C언어 트리
알고리즘/자료구조2023. 8. 24. 17:05C언어 트리

Source Code#include /* 8 / \ 3 10 / \ \ 2 5 14 / \ 11 16*///최대 노드 수를 저장할 변수int MAX_node = 16;// 트리를 저장할 배열//tree[0]에는 노드갯수를 삽입한다.//tree에서 빈부분은 -1로 표현한다.int tree[] = { 8, 8, 3, 18, 2, -1, -1, 21, -1, -1, -1, -1, -1, -1, 11, -1 };//노드의 왼쪽 자식 노드//배열 tree의 원소들을 반환하므로 반환값 int , tree의 인덱스의 값을 매개변수로 받아야 하므로 int index라 작성int get_left_child(int index){ // 노드가 n..

C언어 스택
알고리즘/자료구조2023. 8. 24. 17:04C언어 스택

Source Code#include #include #define STACK_SIZE 100typedef int element; // 스택 원소(element)의 자료형을 int로 정의 typedef struct stack{ element stack[STACK_SIZE]; // 1차원 배열 스택 선언 int top; // top 초기화}StackType;// 스택이 공백 상태인지 확인하는 연산int isEmpty(StackType* s){ if (s->top == -1) //이게 스택이 공백인 조건 //1부터 시작하는 스택이면 top이==0일때 공백 return 1; else return 0;}// 스택이 포화 상태인지 확인하는 연산int isFull(Stack..

C언어 이중 연결 리스트
알고리즘/자료구조2023. 8. 24. 17:04C언어 이중 연결 리스트

Source Code#include #include #include // 이중 연결 리스트의 노드 구조를 구조체로 정의typedef struct listNode{ char name[50]; // 이름 저장 char phone[50];// 전화번호 저장 struct listNode* llink; // 노드의 이전노드를 가리킴 (왼쪽 링크필드) struct listNode* rlink; // 노드의 다음노드를 가리킴 (오른쪽 링크필드)} listNode;// 리스트 시작을 나타내는 head 노드를 구조체로 정의typedef struct{ listNode* head; // listNode구조체의 멤버로 구조체 포인터 변수 head 선언 } linkedList_h;// 공백 이중 연결 리스트를 생성하는 연산 (..

C언어 연결리스트 -요일 삽입
알고리즘/자료구조2023. 8. 24. 17:03C언어 연결리스트 -요일 삽입

Source Code#include #include #include typedef struct ListNode{ char data[4]; struct ListNode* link;} listNode;typedef struct{ listNode* head;} 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->he..

C언어 연결리스트
알고리즘/자료구조2023. 8. 24. 17:03C언어 연결리스트

Source Code#include #include #include typedef struct ListNode{ char data[4]; struct ListNode* link;} listNode;typedef struct{ listNode* head;} 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->hea..

C언어 단순 연결 리스트
알고리즘/자료구조2023. 8. 24. 17:02C언어 단순 연결 리스트

Source Code1#include #include #include // 단순 연결 리스트의 노드 구조를 구조체로 정의typedef struct ListNode { char data[4]; struct ListNode* link;} listNode;// 리스트의 시작을 나타내는 head 노드를 구조체로 정의typedef struct { listNode* head;} linkedList_h;// 공백 연결 리스트를 생성하는 연산linkedList_h* createLinkedList_h(void) { linkedList_h* L; L = (linkedList_h*)malloc(sizeof(linkedList_h)); L->head = NULL; // 공백 리스트이므로 NULL로 설정 return L;}/..

C언어 포인터
알고리즘/자료구조2023. 8. 24. 17:02C언어 포인터

Source Code#include void main(){ char* ptrArray[2]; char** ptrptr; int i; ptrArray[0] = "Korea"; ptrArray[1] = "Seoul"; ptrptr = ptrArray; printf("\n ptrArray[0]의 주소 (&ptrArray[0]) = %u", &ptrArray[0]); printf("\n ptrArray[0]의 값 (ptrArray[0]) = %u", ptrArray[0]); printf("\n ptrArray[0]의 참조값 (*ptrArray[0]) = %c", *ptrArray[0]); printf("\n ptrArray[0]의 참조문자열 (*ptrArray[0]) = %s \n", *ptrArray); pr..

image