๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป Extracurricular/MENTORING

[SOS CLASS] ์ž๋ฃŒ๊ตฌ์กฐ๊ธฐ์ดˆ - 4์ฐจ์‹œ

 


โœ… ์˜ค๋Š˜์˜ ์ง„๋„ (2022/04/15)

1. ์—ฐ๊ฒฐ ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์ดํ•ด

 

2. ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

- ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐœ๋…
- ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์‚ฝ์ž…๊ณผ ์‚ญ์ œ
- ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

3. ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

 

4. ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

 

5. ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์‘์šฉ ๋ฐ ๊ตฌํ˜„


 โœ… ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ ๊ตฌ์กฐ


โœ… ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์—์„œ ์›์†Œ ์‚ฝ์ž…

1. ์‚ฝ์ž…ํ•  ๋…ธ๋“œ ์ค€๋น„ : ๊ณต๋ฐฑ ๋…ธ๋“œ๋ฅผ ๊ฐ€์ ธ์™€ ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ new๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ํ•จ

2. ์ƒˆ ๋…ธ๋“œ์˜ ๋ฐ์ดํ„ฐ ํ•„๋“œ ๊ฐ’ ์ €์žฅ : new์˜ ๋ฐ์ดํ„ฐ ํ•„๋“œ์— "์ˆ˜"๋ฅผ ์ €์žฅ

3. ์ƒˆ ๋…ธ๋“œ์˜ ๋งํฌ ํ•„๋“œ ๊ฐ’ ์ง€์ •

4. ๋ฆฌ์ŠคํŠธ์˜ ์•ž ๋…ธ๋“œ์— ์ƒˆ ๋…ธ๋“œ ์—ฐ๊ฒฐ

 

โšก ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ ์‚ฝ์ž… ์•Œ๊ณ ๋ฆฌ์ฆ˜


โœ… ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์—์„œ ์›์†Œ ์‚ญ์ œ

 

1. ์•ž ๋…ธ๋“œ๋ฅผ ์ฐพ์Œ

2. ์•ž ๋…ธ๋“œ์— ์‚ญ์ œํ•  ๋…ธ๋“œ์˜ ๋งํฌ ํ•„๋“œ ๊ฐ’ ์ €์žฅ (์›”์˜ ๋งํฌ์— ์ˆ˜์˜ ๋งํฌ 200 ์ €์žฅ)

3. ์‚ญ์ œํ•œ ๋…ธ๋“œ์˜ ์•ž๋’ค ๋…ธ๋“œ ์—ฐ๊ฒฐ

 

โšก ๋‹จ์ˆœ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ ์‚ญ์ œ ์•Œ๊ณ ๋ฆฌ์ฆ˜


โœ… ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

โšก ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ ๋ฒˆ์งธ ๋…ธ๋“œ ์‚ฝ์ž… ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

โšก ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ ๋ฒˆ์งธ ๋…ธ๋“œ ์‚ฝ์ž… ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

โšก ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ ์‚ญ์ œ ์•Œ๊ณ ๋ฆฌ์ฆ˜


โœ… ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

โšก ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ ๊ตฌ์กฐ์™€ ๊ตฌ์กฐ์ฒด

 

โšก ์ด์ค‘ ์›ํ˜• ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

 

โšก ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์— ๋…ธ๋“œ ์‚ฝ์ž… ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

โšก ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์— ๋…ธ๋“œ ์‚ญ์ œ ์•Œ๊ณ ๋ฆฌ์ฆ˜

 


โœ… ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ์˜ ์‘์šฉ ๋ฐ ๊ตฌํ˜„

โšก ๋‹คํ•ญ์‹ ๋…ธ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ ํ‘œํ˜„

ex) A(x) = 4x^3 + 3x^2 + 2 

 

โšก ๋‹คํ•ญ์‹ ๋์— ํ•ญ ์ถ”๊ฐ€ ์•Œ๊ณ ๋ฆฌ์ฆ˜

 


 โœ… ๊ด€๋ จ ์ฝ”๋“œ

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

typedef struct ListNode{
	char data[10];
	struct ListNode* link;
} ListNode;

typedef struct{
	listNode* head;
} linkedList_h;

linkedList_h* createLinkedList_h(void);
void freeLinkedList_h(linkedList_h*);
void addLastNode(linkedList_h*, char*);
void reverse(linkedList_h*);
void deleteLastNode(linkedList_h*);
void printList(linkedList_h*);


linkedList_h* createLinkedList_h(void){
	linkedList_h* L;
	L = (linkedList_h*)malloc(sizeof(linkedList_h));
	L -> head = NULL;
	return L;
}

void addLastNode(linkedList_h* L, char* x){
	listNode* newNode;
	listNode* p;
	newNode = (listNode*)malloc(sizeof(listNode));
	strcpy(newNode->data, x);
	newNode->link= NULL;
	if (L->head == NULL){
		L->head = newNode;
		return;
	}
	p = L->head;
	while (p->link != NULL) {
		p = p->link;
	}
	p ->link = newNode;
}

void reverse(linkedList_h * L){
	listNode* p;
	listNode* q;
	listNode* r;

	p = L->head;
	q=NULL;
	r=NULL;

	while (p!= NULL){
		r = q;
		q = p;
		p = p->link;
		q->link = r;
	}
	L->head = q;

}

void deleteLastNode(linkedList_h * L){
	listNode* previous;
	listNode* current;
	if (L->head == NULL) return;
	if (L->head->link == NULL) {
		free(L->head);
		L->head = NULL;
		return;
	}
	else {
		previous = L->head;
		current = L->head->link;
		while(current ->link != NULL){
			previous = current;
			current = current->link;
		}
	free(current);
	previous->link = NULL;
	}
}

void freeLinkedList_h(linkedList_h* L){
	listNode* p;
	while(L->head != NULL){
		p = L->head;
		L->head = L->head->link;
		free(p);
		p=NULL;
	}
}


void printList(linkedList_h* L){
	listNode* p;
	printf("L = (");
	p= L->head;
	while(p != NULL){
		printf("%s", p->data);
		p = p->link;
		if(p != NULL){
			printf(", ");
		}
	}
	printf(") \n");
}


int main(){
	linkedList_h* L;
	L = createLinkedList_h();
	printf("(1) ๊ณต๋ฐฑ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑํ•˜๊ธฐ! \n");
	printList(L); getchar();

	printf("(2) ๋ฆฌ์ŠคํŠธ์— 3๊ฐœ์˜ ๋…ธ๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ! \n");
	addLastNode(L, "์›”");
	addLastNode(L, "์ˆ˜");
	addLastNode(L, "๊ธˆ");	
	printList(L);  getchar();

	printf("(3) ๋ฆฌ์ŠคํŠธ ๋งˆ์ง€๋ง‰์— ๋…ธ๋“œ ํ•œ๊ฐœ ์ถ”๊ฐ€ํ•˜๊ธฐ! \n");
	addLastNode(L, "์ผ");	
	printList(L); getchar();

	printf("(4) ๋งˆ์ง€๋ง‰ ๋…ธ๋“œ ์‚ญ์ œํ•˜๊ธฐ! \n");
	deleteLastNode(L);
	printList(L);  getchar();

	printf("(5) ๋ฆฌ์ŠคํŠธ ์›์†Œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ! \n");
	reverse(L);	
	printList(L);  getchar();

	printf("(6) ๋ฆฌ์ŠคํŠธ ๊ณต๊ฐ„์„ ํ•ด์ œํ•˜์—ฌ, ๊ณต๋ฐฑ๋ฆฌ์ŠคํŠธ ์ƒํƒœ๋กœ ๋งŒ๋“ค๊ธฐ! \n");
	freeLinkedList_h(L);
	printList(L);

	getchar();
	return 0;
}

 

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

typedef struct ListNode{
	float coef;
	int expo;
	struct ListNode* link;
} ListNode;

typedef struct ListHead{
	ListNode* head;
} ListHead;


ListHead* createLinkedList(void)
{
	ListHead* L;
	L = (ListHead *)malloc(sizeof(ListHead));
	L->head = NULL;
	return L;
}

void addLastNode(ListHead* L, float coef, int expo)
{
	ListNode* newNode;
	ListNode* p;
	newNode = (ListNode *)malloc(sizeof(ListNode));
	newNode->coef = coef;
	newNode->expo = expo;
	newNode->link = NULL;
	if(L->head == NULL){
		L->head = newNode;
		return;
	}
	else {
		p = L->head;
		while(p->link != NULL) {
			p = p->link;
		}
		p->link = newNode;
	}
}

void addPoly(ListHead* A, ListHead* B, ListHead* C)
{
	ListNode* pA = A->head;
	ListNode* pB = B->head;
	float sum; 

	while(pA && pB){
		if(pA->expo == pB->expo){
			sum = pA->coef + pB->coef;
			addLastNode(C, sum, pA->expo);
			pA=pA->link;   pB=pB->link;
		}
		else if(pA->expo > pB->expo){			
			addLastNode(C, pA->coef, pA->expo);
			pA=pA->link; 
		}
		else {			
			addLastNode(C, pB->coef, pB->expo);
			pB=pB->link; 
		}
	} 

	for( ; pA!=NULL; pA=pA->link)
		addLastNode(C, pA->coef, pA->expo);

	for( ; pB!=NULL; pB=pB->link)
		addLastNode(C, pB->coef, pB->expo);
}

void printPoly(ListHead* L)
{
	ListNode* p = L->head;
	for(;p;p=p->link){
		printf("%3.0fx^%d", p->coef, p->expo);
	}
}

void main(void){
	ListHead *A, *B, *C;

	A = createLinkedList();
	B = createLinkedList();
	C = createLinkedList();

	addLastNode(A, 4,3);
	addLastNode(A, 3,2);
	addLastNode(A, 5,1);
	printf("\n A(x)=");
	printPoly(A);

	addLastNode(B, 3,4);
	addLastNode(B, 1,3);
	addLastNode(B, 2,1);
	addLastNode(B, 1,0);
	printf("\n B(x)=");
	printPoly(B);

	addPoly(A, B, C);
	printf("\n C(x)=");
	printPoly(C);

	getchar();
}

 


โœ… ์˜ค๋Š˜์˜ ๊ณผ์ œ

SOS CLASS ์ž๋ฃŒ๊ตฌ์กฐ๊ธฐ์ดˆ - 4์ฐจ์‹œ ๊ณผ์ œ.hwp
0.03MB