U E D R , A S I H C RSS

자료구족발보쌈/1110

Difference between r1.1 and the current

@@ -1,4 +1,4 @@
''__INTRO__''
''이게 쉬운거...''
[[TableOfContents]]

= 참여자 명단 =
@@ -8,7 +8,7 @@
|| 박인서 || 출석 ||
|| 이원준 || 출석 ||
|| 남헌 || 출석 ||
전원 출석!!
전원 출석!!+회식!!

= 수업 =
== 진행 ==
@@ -153,7 +153,170 @@
}}}

== 이원준 ==
{{{
#include<stdio.h>
 
typedef struct _node{
struct _node *Rnode;
struct _node *Lnode;
int var;
} node;
 
typedef struct _PQ{
node *one;
} PQ;
void insert(PQ *head, int input){
node *temp = (node*)malloc(sizeof(node));
 
temp->Lnode = NULL;
temp->Rnode = NULL;
temp->var = input;
 
if (head->one == NULL){
head->one = temp;
return;
}
 
node *dir = head->one;
while (1){
if (dir->var < input){
if (dir->Rnode == NULL){
dir->Rnode = temp;
break;
}
else{
dir = dir->Rnode;
}
}
else{
if (dir->Lnode == NULL){
dir->Lnode = temp;
break;
}
else{
dir = dir->Lnode;
}
}
}
}
 
void del(PQ *head, int input){
node *temp1;
node *temp2;
if (head->one == NULL){
printf("없어 없다고!빼에에엑\n");
return;
}
node *dir;
if (head->one->var == input){
temp1 = head->one->Lnode;
temp2 = head->one->Rnode;
printf("있엉: %d\n", head->one->var);
head->one = temp1;
dir = head->one;
if (temp1 == NULL){
head->one = temp2;
return;
}
else{
while (dir->Rnode != NULL){
dir = dir->Rnode;
}

dir->Rnode = temp2;
}
return;
}
 
dir = head->one;
 
while (1){
if (dir->var < input){
if (dir->Rnode == NULL){
printf("없어\n");
return;
}
else{
if (dir->Rnode->var == input){
printf("있엉: %d\n", input);
temp1 = dir->Rnode->Rnode;
temp2 = dir->Rnode->Lnode;
dir->Rnode = temp1;
if (temp1 == NULL){
dir->Rnode = temp2;
return;
}
while (dir->Rnode != NULL){
dir = dir->Rnode;
}
dir->Rnode = temp2;
break;
return;
}
dir = dir->Rnode;
}
}
else{
if (dir->Lnode == NULL){
printf("없어\n");
return;
}
else{
if (dir->Lnode->var == input){
printf("있엉: %d\n", input);
if (dir->Lnode->var == input){
temp1 = dir->Lnode->Rnode;
temp2 = dir->Lnode->Lnode;
dir->Lnode = temp1;
if (temp1 == NULL){
dir->Lnode = temp2;
return;
}
while (dir->Rnode != NULL){
dir = dir->Rnode;
}
dir->Rnode = temp2;
break;
return;
}
dir = dir->Rnode;
}
dir = dir->Lnode;
}
}
}
}
 
 
 
void main(){
PQ *PQhead = (PQ *)malloc(sizeof(PQ));
PQhead->one = NULL;
int i;
insert(PQhead, 10);
insert(PQhead, 5);
insert(PQhead, 20);
insert(PQhead, 100);
insert(PQhead, 30);
insert(PQhead, 1);
del(PQhead, 10);
del(PQhead, 10);
del(PQhead, 20);
del(PQhead, 5);
del(PQhead, 100);
del(PQhead, 30);
del(PQhead, 1);
 
del(PQhead, 10);
del(PQhead, 5);
del(PQhead, 20);
del(PQhead, 100);
del(PQhead, 30);
del(PQhead, 1);
}
}}}
== 남헌 ==

----


이게 쉬운거...


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. 이원준

#include<stdio.h>

typedef struct _node{
	struct _node *Rnode;
	struct _node *Lnode;
	int var;
} node;

typedef struct _PQ{
	node *one;
} PQ;
void insert(PQ *head, int input){
	node *temp = (node*)malloc(sizeof(node));

	temp->Lnode = NULL;
	temp->Rnode = NULL;
	temp->var = input;

	if (head->one == NULL){
		head->one = temp;
		return;
	}

	node *dir = head->one;
	while (1){
		if (dir->var < input){
			if (dir->Rnode == NULL){
				dir->Rnode = temp;
				break;
			}
			else{
				dir = dir->Rnode;
			}
		}
		else{
			if (dir->Lnode == NULL){
				dir->Lnode = temp;
				break;
			}
			else{
				dir = dir->Lnode;
			}
		}
	}
}

void del(PQ *head, int input){
	node *temp1;
	node *temp2;
	if (head->one == NULL){
		printf("없어 없다고!빼에에엑\n");
		return;
	}
	node *dir;
	if (head->one->var == input){
		temp1 = head->one->Lnode;
		temp2 = head->one->Rnode;
		printf("있엉: %d\n", head->one->var);
		head->one = temp1;
		dir = head->one;
		if (temp1 == NULL){
			head->one = temp2;
			return;
		}
		else{
			while (dir->Rnode != NULL){
				dir = dir->Rnode;
			}

			dir->Rnode = temp2;
		}
		return;
	}

	dir = head->one;
	

	while (1){
		if (dir->var < input){
			if (dir->Rnode == NULL){
				printf("없어\n");
				return;
			}
			else{
				if (dir->Rnode->var == input){
					printf("있엉: %d\n", input);
					temp1 = dir->Rnode->Rnode;
					temp2 = dir->Rnode->Lnode;
					dir->Rnode = temp1;
					if (temp1 == NULL){
						dir->Rnode = temp2;
						return;
					}
					while (dir->Rnode != NULL){
						dir = dir->Rnode;
					}
					dir->Rnode = temp2;
					break;
					return;
				}
				dir = dir->Rnode;	
			}
		}
		else{
			if (dir->Lnode == NULL){
				printf("없어\n");
				return;
			}
			else{
				if (dir->Lnode->var == input){
					printf("있엉: %d\n", input);
					if (dir->Lnode->var == input){
						temp1 = dir->Lnode->Rnode;
						temp2 = dir->Lnode->Lnode;
						dir->Lnode = temp1;
						if (temp1 == NULL){
							dir->Lnode = temp2;
							return;
						}
						while (dir->Rnode != NULL){
							dir = dir->Rnode;
						}
						dir->Rnode = temp2;
						break;
						return;
					}
					dir = dir->Rnode;
					
				}
				dir = dir->Lnode;
			}
		}
	}
}



void main(){
	PQ *PQhead = (PQ *)malloc(sizeof(PQ));
	PQhead->one = NULL;
	int i;
	insert(PQhead, 10);
	insert(PQhead, 5);
	insert(PQhead, 20);
	insert(PQhead, 100);
	insert(PQhead, 30);
	insert(PQhead, 1);
	del(PQhead, 10);
	del(PQhead, 10);
	del(PQhead, 20);
	del(PQhead, 5);
	del(PQhead, 100);
	del(PQhead, 30);
	del(PQhead, 1);

	del(PQhead, 10);
	del(PQhead, 5);
	del(PQhead, 20);
	del(PQhead, 100);
	del(PQhead, 30);
	del(PQhead, 1);
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:38
Processing time 0.0502 sec