[자료구조론] - Data Structure (18) 썸네일형 리스트형 DoubleLinkedList 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667typedef enum {false,true} bool;typedef int Data; typedef struct _Node{ Data item; struct _Node *next; struct _Node *prev;} Node; typedef struct{ Node *head; int len;} DoubleLinkedList; void InitList(DoubleLinkedList *plist){ Node* dummy1, *dummy2; dummy1 = (Node*)malloc(si.. CircularList 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145typedef enum {false,true} bool;typedef int Data; typedef struct _Node{ .. LinkedList Application 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #include LinkedList* Concatenate(LinkedList* plist1, LinkedList* plist2){ if(plist1->head->next == NULL) return plist2; else if(plist2->head->next == NULL) return plist1; else{ Node* cur = plist1->head->next; while(cur->next != NULL){ cur= cur->next; } cur->next = plist2->head->next;.. List 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 #define MAX_LIST 100 typedef enum { false, true } bool; typedef int Data; typedef struct { Data items[MAX_LIST]; int len; } ArrayList; void InitList(ArrayList *plist) { plist->len = 0; } bool IsEmpty(Arr.. Queue 구현 1234567891011121314151617181920212223242526272829303132333435363738394041#define MAX_QUEUE 100 typedef int Data; typedef struct{ int front, rear; Data items[MAX_QUEUE];} Queue; void InitQueue(Queue *pq){ pq->front = pq->rear = 0;}bool IsFull(Queue *pq){ return pq->front == (pq->rear + 1) % MAX_QUEUE;}bool IsEmpty(Queue *pq){ return pq->front == pq->rear;}Data Peek(Queue *pq){ if (IsEmpty(pq)) ex.. [자료구조론] Recursion Recursion이란? 자기자신을 call하는 함수! Base case와 Recursive case로 나누어진다! Base case가 없으면 Stack overflow를 일으킨다! - stack memory가 가득 차게 되기 때문에 Iteration vs Recursion 1) Finding Maximum Number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 //Iteration int findMax(int *arr, int n) { int max = arr[0]; for (int i = 1; i max) max = arr[i]; } return max; } //Recu.. [자료구조론] Stack - 문제 풀이 두 가지 문제를 풀어보고자 한다. 문제 1. '/' , '\' 두 문자로 이루어진 문자열이 있다. 이 문자열을 mountain이라고 생각해서 '/'은 uphill이고 '\' downhill 이라 정의하자. 올바른 mountain은 항상 '/'로 시작하고 '/'에 대응하는 '\'가 항상 존재한다고 가정한다. Ex) Input > blank 없이 string을 입력 받고 길이는 0 올바른 string이라면 그 mountain의 height를 출력한다. > 그렇지 않다면 0을 출력한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 .. [자료구조론] Stack - FIFO # 개념위주보다는 구현 위주로 작성하겠다! Stack에 주로 쓰이는 함수들 Top Push Pop Peek Empty Full 아! 가장 중요한 initStack (스택 초기화 설정 - make stack empty) How does the stack work? 스택은 top index를 제외하고는 어느 곳도 access할 수 없다. Array based Implementation in C 1 2 3 4 5 6 7 #define Stack_Size 100 typedef int Data; typedef struct{ Data items[Stack_Size]; int top; }Stack; cs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 .. 이전 1 2 다음