본문 바로가기

Programming/C, C++6

트리생성 //종료가 -1 이므로 그부분 수정 #include #include struct node { int data; struct node *PL; struct node *PR; }*root,*p,*temp,*del; void preorder(struct node * root) { if(root) { printf("%d ",root->data); preorder(root->PL); preorder(root->PR); } } void inorder(struct node * root) { if(root) { inorder(root->PL); printf("%d ",root->data); inorder(root->PR); } } void postorder(struct node * root) { if(root) { p.. 2013. 5. 21.
수식트리 //수식트리 //발전 가능성 : 지금은 각 노드를 사용자가 직접 입력하도록 해놨다. -> string을 통해 변경해보기 #include #include #define max(a,b) (((a) > (b)) ? (a) : (b)) typedef struct TreeNode { int data; TreeNode *left,*right; }TreeNode; int preorder(TreeNode *root) { int op1, op2; if(root == NULL) // 값이 없는 경우 return 0; if(root->left == NULL && root->right == NULL) {// root만 데이터가 있는 경우 printf("%d ", root->data ); return root->data ; }.. 2013. 5. 21.
Doublelinkedlist //이중연결리스트 발생 자체만 설정함 #include #include struct Node { int value; struct Node *PL;//왼쪽이동링크로 사용됨 struct Node *PR;//오른쪽이동링크로 사용됨 }; int main(void) { struct Node *Head, *tail, *temp, *temp2, *wtf; wtf=(struct Node *)malloc(sizeof(struct Node)); //동적 메모리 설정 wtf->value = 1; wtf->PL = NULL; wtf->PR = NULL; Head = tail = temp = temp2 = wtf; // 위치 다 똑같음 for (int i = 2 ; i < 13; i++) { //데이터 삽입, 이동을 위한 for.. 2012. 12. 26.
Linkedlist //연결리스트 발생 자체만 구현 #include #include struct Node { int value; struct Node *ptr;//링크로 사용됨 }; int main(void) { struct Node *Head, *tail, *temp, *wtf; wtf=(struct Node *)malloc(sizeof(struct Node)); //동적 메모리 설정 wtf->value = 1; wtf->ptr = NULL; Head = tail = temp = wtf; // 위치 다 똑같음 for (int i = 2 ; i value = .. 2012. 12. 26.