''이게 쉬운거...'' [[TableOfContents]] = 참여자 명단 = || 함장 || 장용운 || 11학번 || 출석 || ||<|4> 선원 || 천준현 ||<|4> 15학번 || 출석 || || 박인서 || 출석 || || 이원준 || 출석 || || 남헌 || 출석 || 전원 출석!! = 수업 = == 진행 == 1. 장소 : 6층 학회실 2. 시간 : 15시 ~ 17시 == 내용 == '''수심 4000m. 트리2''' * BST(이진 탐색 트리) = 코드 = == 예제1 == = 숙제 = 1. 고통받기 ---- = 숙제 제출 = == 천준현 == == 박인서 == {{{ #include #include struct node{ int val; struct node * lnext; struct node * rnext; }; void insert(struct node * target, int newval) { struct node * newnode = (struct node *)malloc(sizeof(struct node)); int lr=0; newnode->lnext=NULL,newnode->rnext=NULL,newnode->val=newval; while(1) { if(target->val>=newval) { if(target->lnext==NULL) { lr=-1; break; } target=target->lnext; } else { if(target->rnext==NULL) { lr=1; break; } target=target->rnext; } } if(lr==-1) target->lnext=newnode; else target->rnext=newnode; } int del(struct node * target, int find) { struct node * tlnode; struct node *trnode; struct node * ta; while(1) { if(target->val>find) { if(target->lnext==NULL) return 0; target=target->lnext; } else if(target->valrnext==NULL) return 0; target=target->rnext; } else if(target->val==find) break; else return 0; } tlnode=target->lnext; trnode=target->rnext; ta=target; if(target->rnext==NULL) { if(target->lnext==NULL) { free(ta); return 1; } else target=tlnode; } else { target=trnode; while(target->lnext!=NULL) target=target->lnext; tlnode=target; } ta->lnext=NULL,ta->rnext=NULL; free(ta); return 1; } int main() { struct node * head=(struct node *)malloc(sizeof(struct node)); int ind,t; char ch[10],a; printf("초기값 설정 ㄱㄱ : "); scanf("%d",&ind); head->val=ind; head->lnext=NULL; head->rnext=NULL; while(1) { printf("\ninsert(i)나 delete(d)나 exit(e)를 입력하세요 : "); scanf("%s",ch); a=ch[0]; if(a=='I' || a=='i') { printf("머 집어넣을꺼임? : "); scanf("%d",&ind); insert(head,ind); } else if(a=='D' || a=='d') { printf("머 뺄꺼임? : "); scanf("%d",&ind); if(del(head,ind)) printf("잘 빼짐\n"); else printf("값 없어\n"); } else if(a=='E' || a=='e') break; else printf("제대로 입력하라고\n"); } return 0; } }}} == 이원준 == == 남헌 == ---- ----------------------------------- [활동지도/2015] [자료구족발보쌈]