분류 전체보기129 자료구조) 피보나치 수열 #include int fib(int n) //순환-> 개비효율적{ if (n == 0) return 0; if (n == 1) return 1; return (fib(n - 1) + fib(n - 2));} int fib_iter(int n) //재귀{ if (n 2015. 8. 25. 자료구조) Binary_Tree #include #include typedef struct Node{ int data; Node *left; Node *right;}Node; Node* createNode(int data){ Node* newNode = (Node *)malloc(sizeof(Node)); newNode->left = NULL; newNode->right = NULL; newNode->data = data; return newNode;} Node* searchNode(Node* Tree, int findData){ if (Tree == NULL) return NULL; if (Tree->data == findData) return Tree; else if (Tree->data > findData) searchNode(T.. 2015. 8. 25. 자료구조) Tree_Traverse #include #include struct Node{ int data; Node *left; Node *right;}; Node *Root; void InitTree(int data){ Root = (Node *)malloc(sizeof(Node)); Root->data = data;} Node *AddChild(Node *Parent, int data, bool bLeft){ Node *New; New = (Node *)malloc(sizeof(Node)); New->data = data; New->left = NULL; New->right = NULL; if (bLeft) Parent->left = New; else Parent->right = New; return New;} void PreOrde.. 2015. 8. 25. 자료구조) Graph #include #include /* 인접 행렬을 이용한 그래프 추상 데이터 타입의 구현 */ #define MAX_VERTICES 50typedef struct GraphType{ int n; int adj_mat[MAX_VERTICES][MAX_VERTICES];}GraphType; //그래프 초기화void graph_init(GraphType *g){ int r, c; g->n = 0; for (r = 0; r n) + 1) > MAX_VERTICES) { fprintf(stderr, "그래프:정점의 개수 초과"); return; } g->n++;} //간선 삽입 연산void insert_edge(GraphType *g, int start, int end){ if (start >= g->n || e.. 2015. 8. 25. 자료구조) QuickSort #include #include #define SWAP(a,b) {int t; t = a; a = b; b = t;} void QuickSort(char *ar, int num){ int left, right; char key; //구간이 1이면정렬 끝 if (num = right) break; //좌우가 만나면 끝 SWAP(ar[left], ar[right]); } SWAP(ar[left], ar[num - 1]); //기준값과 i위치의 값 교환 QuickSort(ar, left); //왼쪽 구간 정렬 QuickSort(ar + left + 1, num - left - 1); //오른쪽 구간 정렬} void main(){ char str[] = "greathuman"; printf("정렬 전의 문자열 .. 2015. 8. 25. 자료구조) linked_queue #include #include typedef struct _node{ int data; struct _node *link;}_node; typedef struct _queue{ _node *front; _node *rear;}_queue; void init(_queue *q){ q->front = q->rear = NULL;} int is_empty(_queue *q){ return (q->front == NULL);} void enqueue(_queue *q, int data){ _node *temp; temp = (_node *)malloc(sizeof(_node)); temp->data = data; temp->link = NULL; if (is_empty(q)) { q->front = temp;.. 2015. 8. 25. 이전 1 ··· 18 19 20 21 22 다음