U E D R , A S I H C RSS

자료구족발보쌈/1110 (rev. 1.1)

자료구족발보쌈/1110

INTRO


1. 참여자 명단


함장 장용운 11학번 출석
선원 천준현 15학번 출석
박인서 출석
이원준 출석
남헌 출석
전원 출석!!

2. 수업

2.1. 진행

1. 장소 : 6층 학회실
2. 시간 : 15시 ~ 17시

2.2. 내용

수심 4000m. 트리2
  • BST(이진 탐색 트리)

3. 코드

3.1. 예제1


4. 숙제

1. 고통받기




5. 숙제 제출

5.1. 천준현


5.2. 박인서


#include <stdio.h>
#include <stdlib.h>

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->val<find)
		{
			if(target->rnext==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;
}

5.3. 이원준


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:38
Processing time 0.0202 sec