FIN

mInGΒ·2022λ…„ 12μ›” 4일
0

Data structure

λͺ©λ‘ 보기
9/9

πŸ“Œ 문제 μ†Œκ°œ

쀑간 λ°œν‘œμ—μ„œ μˆ˜ν–‰ν•˜κ³ μž ν•˜λŠ” μ£Όμ œλŠ” 'μ–΄λ–»κ²Œ ν•˜λ©΄ μ“°λ ˆκΈ°λ₯Ό 빨리 μ²˜λ¦¬ν•  수 μžˆμ„κΉŒ?'에 λŒ€ν•œ 방법을 μ°ΎλŠ” κ²ƒμ΄μ—ˆλ‹€. ν•˜λ‹¨μ˜ 링크λ₯Ό 톡해 쀑간 λ°œν‘œμ—μ„œ ν–ˆλ˜ λ‚΄μš©μ„ λ³Ό 수 있고, 이번 기말 λ°œν‘œμ˜ μ£Όμ œλ„ κ°™κΈ΄ ν•˜μ§€λ§Œ μ ‘κ·Ό λ°©λ²•μ—μ„œ μ•½κ°„μ˜ μˆ˜μ •μ„ ν•˜κ²Œ λ˜μ—ˆλ‹€.

https://velog.io/@minkyung2121/%EC%A4%91%EA%B0%84-%EB%B0%9C%ED%91%9C

ν•˜μ²œ μ“°λ ˆκΈ° 처리 κ΄€λ ¨ν•œ 기사λ₯Ό μ°Ύλ‹€κ°€ 'ν•˜μ²œμœΌλ‘œ μœ μž…λ˜λŠ” μ“°λ ˆκΈ° 쀑에 ν”ŒλΌμŠ€ν‹±, 비닐λ₯˜ 등은 μžμ—°ν™˜κ²½μ—μ„œ 잘 λΆ„ν•΄λ˜μ§€ μ•Šμ•„ ν•˜μ²œλΏ μ•„λ‹ˆλΌ ν•΄μ–‘ ν™˜κ²½μ— 문제λ₯Ό μΌμœΌν‚¨λ‹€'λΌλŠ” λ¬Έμž₯을 읽게 λ˜μ—ˆλ‹€.

이것을 톡해 λ‚΄κ°€ ν•΄κ²°ν•˜κ³ μž ν•˜λŠ” λ¬Έμ œλŠ” μœ„μ— 써놓은 μ£Όμ œμ™€ κ°™λ‹€. λΆ€μ—° μ„€λͺ…을 ν•˜μžλ©΄ μœ„λ„, 경도, μ“°λ ˆκΈ°μ˜ μ’…λ₯˜λ₯Ό μ•Œ 수 μžˆλŠ” data csv 파일이 μžˆλ‹€. ν•˜λ‚˜μ˜ μ‹œμž‘ 지점을 μ •ν•˜μ—¬ λ‹€λ₯Έ ν•œ μ§€μ κΉŒμ§€ λ„μ°©ν•˜λŠ” μ΅œλ‹¨ 경둜λ₯Ό κ΅¬ν•˜λŠ” 것이 λͺ©ν‘œμ΄λ‹€.

문제λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œ 방법

  1. λ¨Όμ € λ°©λ¬Έν•΄μ•Όν•˜λŠ” λ…Έλ“œλ₯Ό μ •ν•˜μ—¬ μ•Œκ³ λ¦¬μ¦˜μ„ μ‚¬μš©ν•΄ 졜적의 경둜λ₯Ό νƒμƒ‰ν•œλ‹€.
  2. λ°©λ¬Έ μˆœμ„œλ₯Ό μ €μž₯ν•˜λŠ” 배열을 μƒμ„±ν•œ λ’€, λ°©λ¬Έ μ—¬λΆ€λ₯Ό μ €μž₯ν•˜λŠ” 배열을 μƒμ„±ν•˜μ—¬ True/False둜 ν™•μΈν•œλ‹€.
  3. μ‹œμž‘ λ…Έλ“œλ‘œλΆ€ν„° λ…Έλ“œλ₯Ό κ±°μ³μ„œ κ°€λŠ” λͺ¨λ“  λ…Έλ“œλ₯Ό νƒμƒ‰ν•œλ‹€.
  4. λ°©λ¬Έν•˜μ§€ μ•Šμ€ λ…Έλ“œλ₯Ό νƒμƒ‰ν•˜κ³  λλ‚¬μœΌλ©΄ 처음 μ§€μ μœΌλ‘œ λŒμ•„κ°„λ‹€.
  5. νƒμƒ‰ν•œ κ²½λ‘œκ°€ μ΅œλ‹¨ 경둜일 λ•Œ 값을 μ—…λ°μ΄νŠΈν•˜κ³  μˆœμ„œμ™€ λ°©λ¬Έ μ—¬λΆ€ 배열에 값을 μ €μž₯ν•œλ‹€.

πŸ“Œ 데이터 μ†Œκ°œ

μžλ£Œκ΅¬μ‘°μ‹€μŠ΅ μˆ˜μ—…μ„ λ“£λŠ” ν™”μš”μΌκ³Ό μˆ˜μš”μΌ λΆ„λ°˜μ˜ 59개 데이터 csv 파일 μ€‘μ—μ„œ λ‚˜λŠ” 36λͺ…μ˜ 학생, 100개의 데이터λ₯Ό μ‚¬μš©ν•˜μ˜€λ‹€.

데이터 μ‚¬μš© 방법

  1. csv 파일 쀑 μœ„λ„, 경도 값을 μ‚¬μš©ν•˜μ—¬ 거리 값을 κ΅¬ν•˜λŠ” 곡식에 λŒ€μž…
  2. center(μ‹œμž‘κ°’)을 노원 μžμ›νšŒμˆ˜ μ‹œμ„€μ˜ μœ„λ„, 경도 κ°’μœΌλ‘œ μ§€μ •ν•œ ν›„ point(점)κ³Ό center의 거리λ₯Ό μ†Œμˆ˜μ  2번째 μžλ¦¬κΉŒμ§€ λ‚˜μ˜€λ„λ‘ μ„€μ •
  3. 이λ₯Ό 톡해 노원 μžμ›νšŒμˆ˜ μ‹œμ„€κ³Ό μ“°λ ˆκΈ° 사진을 찍은 κ³³ μ‚¬μ΄μ˜ 거리λ₯Ό μ•Œ 수 있음

μ‚¬μ΄μ˜ 거리λ₯Ό κ΅¬ν•˜κΈ° μœ„ν•΄ μž‘μ„±ν•œ distance.cpp μ½”λ“œλ₯Ό μ²¨λΆ€ν•˜μ˜€λ‹€.
μœ„λ„μ™€ 경도가 κ²ΉμΉ˜λŠ” 데이터가 μ—†κ²Œ ν•˜κΈ° μœ„ν•˜μ—¬ (쀑볡값 방지) λͺ¨λ‘ λ‹€λ₯Έ 데이터λ₯Ό μ‚¬μš©ν•˜μ˜€λ‹€. μ†Œμˆ˜μ  λ‘˜μ§Έ μžλ¦¬κΉŒμ§€ μžˆλŠ” 데이터λ₯Ό μˆ˜μ§‘ν•˜λ©΄μ„œ 100κ°œκ°€ λ‹€ μ±„μ›Œμ§€μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ— 본인의 데이터 정보λ₯Ό μ‚¬μš©ν•œκ²ƒλ„ μžˆλ‹€.

#define _USE_MATH_DEFINES
#include <stdio.h>
#include "math.h"

class LatLong {
public:
    double latitude = 0;
    double longitude = 0;

    LatLong(double _lat, double _long) {
        latitude = _lat;
        longitude = _long;
    }
};

// return : KM
double calcDistance(LatLong start, LatLong end) {
    double distance = 0;

    double startLatitudeRadian = start.latitude * M_PI / 180;   // M_PI = 3.141592..
    double startLongitudeRadian = start.longitude * M_PI / 180;
    double endLatitudeRadian = end.latitude * M_PI / 180;
    double endLongitudeRadian = end.longitude * M_PI / 180;

    distance = acos(sin(startLatitudeRadian) * sin(endLatitudeRadian) + cos(startLatitudeRadian) * cos(endLatitudeRadian) * cos(endLongitudeRadian - startLongitudeRadian));

    distance = distance * 6371;

    return distance;
}

int main()
{
    LatLong center(37.64, 127.05); // 노원 μžμ›νšŒμˆ˜ μ‹œμ„€

    LatLong point1(37.49, 127.06); 
    LatLong point2(37.49, 127.07); 
    LatLong point3(37.50, 127.07); 
    LatLong point4(37.47, 127.07);  
    LatLong point5(37.51, 127.07);  
    LatLong point6(37.50, 127.06);  
    LatLong point7(37.52, 127.06);  
    LatLong point8(37.48, 127.05);  
    LatLong point9(37.52, 126.93);  
    LatLong point10(37.51, 127.06);  
    LatLong point11(37.48, 127.04);  
    LatLong point12(37.51, 127.08);  
    LatLong point13(37.52, 127.09);  
    LatLong point14(37.53, 126.92);  
    LatLong point15(37.58, 127.04);  
    LatLong point16(37.65, 127.01);  
    LatLong point17(37.59, 127.01);   
    LatLong point18(37.58, 127.01);   
    LatLong point19(37.54, 127.03);  
    LatLong point20(37.58, 127.01); 
    LatLong point21(37.59, 126.94); 
    LatLong point22(37.53, 126.88); 
    LatLong point23(37.54, 126.88); 
    LatLong point24(37.53, 126.89); 
    LatLong point25(37.52, 126.93); 
    LatLong point26(37.53, 126.93); 
    LatLong point27(37.51, 126.93); 
    LatLong point28(37.57, 126.90); 
    LatLong point29(37.57, 126.92); 
    LatLong point30(37.59, 127.02); 
    LatLong point31(37.52, 126.87); 
    LatLong point32(37.64, 127.11); 
    LatLong point33(37.31, 127.08); 
    LatLong point34(37.32, 127.08); 
    LatLong point35(37.59, 127.00); 
    LatLong point36(37.59, 127.10); 
    LatLong point37(37.58, 127.01); 
    LatLong point38(37.49, 127.11);  
    LatLong point39(37.49, 127.10);  
    LatLong point40(37.56, 127.00);  
    LatLong point41(37.51, 127.10); 
    LatLong point42(37.50, 127.10); 
    LatLong point43(37.50, 127.09); 
    LatLong point44(37.55, 126.90); 
    LatLong point45(37.52, 126.94); 
    LatLong point46(37.46, 126.83); 
    LatLong point47(37.46, 126.84); 
    LatLong point48(37.48, 126.90); 
    LatLong point49(37.31, 126.55); 
    LatLong point50(37.32, 126.55); 
    LatLong point51(37.48, 126.81); 
    LatLong point52(37.55, 126.88); 
    LatLong point53(37.56, 126.89); 
    LatLong point54(37.57, 126.86); 
    LatLong point55(37.57, 126.89); 
    LatLong point56(37.59, 126.75); 
    LatLong point57(37.59, 126.75); 
    LatLong point58(37.27, 127.46); 
    LatLong point59(36.98, 127.93); 
    LatLong point60(36.98, 127.94); 
    LatLong point61(36.97, 127.94); 
    LatLong point62(37.60, 127.01); 
    LatLong point63(37.66, 126.62); 
    LatLong point64(37.63, 126.54); 
    LatLong point65(37.70, 126.60); 
    LatLong point66(37.63, 126.70); 
    LatLong point67(37.43, 126.37); 
    LatLong point68(37.46, 127.09); 
    LatLong point69(37.53, 127.10); 
    LatLong point70(37.53, 127.22); 
    LatLong point71(37.56, 127.19); 
    LatLong point72(37.33, 127.11); 
    LatLong point73(37.53, 127.07); 
    LatLong point74(37.55, 127.22); 
    LatLong point75(37.67, 126.82); 
    LatLong point76(37.56, 127.18); 
    LatLong point77(38.19, 128.60); 
    LatLong point78(35.16, 129.14); 
    LatLong point79(37.49, 127.04); 
    LatLong point80(37.49, 126.98); 
    LatLong point81(37.47, 126.79); 
    LatLong point82(37.47, 126.80); 
    LatLong point83(37.56, 126.97); 
    LatLong point84(37.31, 126.54); 
    LatLong point85(37.35, 127.10); 
    LatLong point86(37.28, 126.55); 
    LatLong point87(37.29, 126.55); 
    LatLong point88(37.32, 127.10); 
    LatLong point89(37.49, 126.87); 
    LatLong point90(37.50, 126.87); 
    LatLong point91(37.60, 126.80); 
    LatLong point92(37.59, 126.80); 
    LatLong point93(37.00, 127.00); 
    LatLong point94(35.01, 127.00); 
    LatLong point95(37.67, 126.81); 
    LatLong point96(37.63, 126.92); 
    LatLong point97(37.63, 126.71); 
    LatLong point98(37.39, 126.46); 
    LatLong point99(37.39, 126.42); 
    LatLong point100(37.44, 126.43); 

    printf("point1: %.2f km\n", calcDistance(point1, center)); 
    printf("point2: %.2f km\n", calcDistance(point2, center));
    printf("point3: %.2f km\n", calcDistance(point3, center));
    printf("point4: %.2f km\n", calcDistance(point4, center));
    printf("point5: %.2f km\n", calcDistance(point5, center));
    printf("point6: %.2f km\n", calcDistance(point6, center));
    printf("point7: %.2f km\n", calcDistance(point7, center));
    printf("point8: %.2f km\n", calcDistance(point8, center));
    printf("point9: %.2f km\n", calcDistance(point9, center));
    printf("point10: %.2f km\n", calcDistance(point10, center));
    printf("point11: %.2f km\n", calcDistance(point11, center));
    printf("point12: %.2f km\n", calcDistance(point12, center));
    printf("point13: %.2f km\n", calcDistance(point13, center));
    printf("point14: %.2f km\n", calcDistance(point14, center));
    printf("point15: %.2f km\n", calcDistance(point15, center));
    printf("point16: %.2f km\n", calcDistance(point16, center));
    printf("point17: %.2f km\n", calcDistance(point17, center));
    printf("point18: %.2f km\n", calcDistance(point18, center));
    printf("point19: %.2f km\n", calcDistance(point19, center));
    printf("point20: %.2f km\n", calcDistance(point20, center));
    printf("point21: %.2f km\n", calcDistance(point21, center));
    printf("point22: %.2f km\n", calcDistance(point22, center));
    printf("point23: %.2f km\n", calcDistance(point23, center));
    printf("point24: %.2f km\n", calcDistance(point24, center));
    printf("point25: %.2f km\n", calcDistance(point25, center));
    printf("point26: %.2f km\n", calcDistance(point26, center));
    printf("point27: %.2f km\n", calcDistance(point27, center));
    printf("point28: %.2f km\n", calcDistance(point28, center));
    printf("point29: %.2f km\n", calcDistance(point29, center));
    printf("point30: %.2f km\n", calcDistance(point30, center));
    printf("point31: %.2f km\n", calcDistance(point31, center));
    printf("point32: %.2f km\n", calcDistance(point32, center));
    printf("point33: %.2f km\n", calcDistance(point33, center));
    printf("point34: %.2f km\n", calcDistance(point34, center));
    printf("point35: %.2f km\n", calcDistance(point35, center));
    printf("point36: %.2f km\n", calcDistance(point36, center));
    printf("point37: %.2f km\n", calcDistance(point37, center));
    printf("point38: %.2f km\n", calcDistance(point38, center));
    printf("point39: %.2f km\n", calcDistance(point39, center));
    printf("point40: %.2f km\n", calcDistance(point40, center));
    printf("point41: %.2f km\n", calcDistance(point41, center));
    printf("point42: %.2f km\n", calcDistance(point42, center));
    printf("point43: %.2f km\n", calcDistance(point43, center));
    printf("point44: %.2f km\n", calcDistance(point44, center));
    printf("point45: %.2f km\n", calcDistance(point45, center));
    printf("point46: %.2f km\n", calcDistance(point46, center));
    printf("point47: %.2f km\n", calcDistance(point47, center));
    printf("point48: %.2f km\n", calcDistance(point48, center));
    printf("point49: %.2f km\n", calcDistance(point49, center));
    printf("point50: %.2f km\n", calcDistance(point50, center));
    printf("point51: %.2f km\n", calcDistance(point51, center));
    printf("point52: %.2f km\n", calcDistance(point52, center));
    printf("point53: %.2f km\n", calcDistance(point53, center));
    printf("point54: %.2f km\n", calcDistance(point54, center));
    printf("point55: %.2f km\n", calcDistance(point55, center));
    printf("point56: %.2f km\n", calcDistance(point56, center));
    printf("point57: %.2f km\n", calcDistance(point57, center));
    printf("point58: %.2f km\n", calcDistance(point58, center));
    printf("point59: %.2f km\n", calcDistance(point59, center));
    printf("point60: %.2f km\n", calcDistance(point60, center));
    printf("point61: %.2f km\n", calcDistance(point61, center));
    printf("point62: %.2f km\n", calcDistance(point62, center));
    printf("point63: %.2f km\n", calcDistance(point63, center));
    printf("point64: %.2f km\n", calcDistance(point64, center));
    printf("point65: %.2f km\n", calcDistance(point65, center));
    printf("point66: %.2f km\n", calcDistance(point66, center));
    printf("point67: %.2f km\n", calcDistance(point67, center));
    printf("point68: %.2f km\n", calcDistance(point68, center));
    printf("point69: %.2f km\n", calcDistance(point69, center));
    printf("point70: %.2f km\n", calcDistance(point70, center));
    printf("point71: %.2f km\n", calcDistance(point71, center));
    printf("point72: %.2f km\n", calcDistance(point72, center));
    printf("point73: %.2f km\n", calcDistance(point73, center));
    printf("point74: %.2f km\n", calcDistance(point74, center));
    printf("point75: %.2f km\n", calcDistance(point75, center));
    printf("point76: %.2f km\n", calcDistance(point76, center));
    printf("point77: %.2f km\n", calcDistance(point77, center));
    printf("point78: %.2f km\n", calcDistance(point78, center));
    printf("point79: %.2f km\n", calcDistance(point79, center));
    printf("point80: %.2f km\n", calcDistance(point80, center));
    printf("point81: %.2f km\n", calcDistance(point81, center));
    printf("point82: %.2f km\n", calcDistance(point82, center));
    printf("point83: %.2f km\n", calcDistance(point83, center));
    printf("point84: %.2f km\n", calcDistance(point84, center));
    printf("point85: %.2f km\n", calcDistance(point85, center));
    printf("point86: %.2f km\n", calcDistance(point86, center));
    printf("point87: %.2f km\n", calcDistance(point87, center));
    printf("point88: %.2f km\n", calcDistance(point88, center));
    printf("point89: %.2f km\n", calcDistance(point89, center));
    printf("point90: %.2f km\n", calcDistance(point90, center));
    printf("point91: %.2f km\n", calcDistance(point91, center));
    printf("point92: %.2f km\n", calcDistance(point92, center));
    printf("point93: %.2f km\n", calcDistance(point93, center));
    printf("point94: %.2f km\n", calcDistance(point94, center));
    printf("point95: %.2f km\n", calcDistance(point95, center));
    printf("point96: %.2f km\n", calcDistance(point96, center));
    printf("point97: %.2f km\n", calcDistance(point97, center));
    printf("point98: %.2f km\n", calcDistance(point98, center));
    printf("point99: %.2f km\n", calcDistance(point99, center));
    printf("point100: %.2f km\n", calcDistance(point100, center));

    return 0;
}

distanceλ₯Ό κ΅¬ν•˜κ³  이λ₯Ό ν™œμš©ν•΄μ„œ λ‹€μ΅μŠ€νŠΈλΌ μ•Œκ³ λ¦¬μ¦˜μ— μ μš©ν•΄μ•Όλœλ‹€.
μ•„λž˜μ— μžˆλŠ” μ½”λ“œλŠ” main.cpp이며 간선듀을 μ—°κ²°κ³Ό 거리값을 λΆ€μ—¬ν•˜μ˜€λ‹€.

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "math.h"
#include <type_traits>

#define MAX_NODE 100
#define INIT_VALUE 100000

typedef struct Typedef_Vertex
{
	int vertex;
	int distance;
	struct Typedef_Vertex* next;
}Typedef_Vertex;

typedef struct Typedef_Graph
{
	struct Typedef_Vertex* Adj_List[MAX_NODE];
}Typedef_Graph;

void AppendNode(Typedef_Graph*, int, int, int);
void DisplayGraph(Typedef_Graph);
void ShortestPath(Typedef_Graph, int, int);
void dijjkstra(Typedef_Graph, int, int);
void SearchPath(int, int);

void AppendNode(Typedef_Graph* g, int from, int to, int distance)
{
	if (from > MAX_NODE || to > MAX_NODE)
	{
		printf("ERROR: 잘λͺ»λœ vertex 번호λ₯Ό μž…λ ₯ν–ˆμŠ΅λ‹ˆλ‹€. \n\n");
		exit(-1);
	}

	Typedef_Vertex* v = (Typedef_Vertex*)malloc(sizeof(Typedef_Vertex));
	Typedef_Graph temp = *g;

	v->next = NULL;

	if (g->Adj_List[from] == NULL)
	{
		v->distance = distance;
		v->vertex = to;
		g->Adj_List[from] = v;
	}
	else
	{
		if (g->Adj_List[from]->distance > distance)
		{
			v->distance = distance;
			v->vertex = to;
			for (; temp.Adj_List[from]->next;
				temp.Adj_List[from] = temp.Adj_List[from]->next);

			temp.Adj_List[from]->next = v;
		}
	}
}

void DisplayGraph(Typedef_Graph graph)
{
	int i;
	Typedef_Graph g = graph;

	printf("\nfrom to\(distance_\n\n");

	for (i = 0; i < MAX_NODE; i++)
	{
		while (g.Adj_List[i] != NULL)
		{
			printf("%2d -> %2d", i, (g.Adj_List[1]->vertex));
			printf("\(%d\)\n", g.Adj_List[i]->distance);
			g.Adj_List[i] = g.Adj_List[1]->next;
		}
	}
	printf("\n\n");
}

const char* city[MAX_NODE] = { "n1", "n2", "n3", "n4", "n5", "n6", "n7" ... "n99", "n100"};
int Distance[MAX_NODE];
int path[MAX_NODE];

void ShortestPath(Typedef_Graph graph, int from, int to)
{
	int i;
	Typedef_Graph g = graph;

	if (from > MAX_NODE || to > MAX_NODE)
	{
		printf("ERROR: 잘λͺ»λœ vertex 번호λ₯Ό μž…λ ₯ν–ˆμŠ΅λ‹ˆλ‹€.\n\n");
		exit(-1);
	}

	for (i = 0; i < MAX_NODE;
		i++,
		Distance[i - 1] = INIT_VALUE,
		path[i - 1] = 1);

	Distance[from] = 0;

	dijkstra(g, from, to);
	printf("*** %sμ—μ„œ %sκΉŒμ§€ ***\n\n", city[from], city[to]);

	if (Distance[to] != INIT_VALUE)
	{
		printf("1. %-15s \[%d]\n", "D I S T A N C E", Distance[to]);
		SearchPath(from, to);
	}
	else
	{
		printf("경둜 μ—†μŒ\n");
	}
}

typedef struct QueueData
{
	int value;
	struct QueueData* NEXT;
}QueueData;

QueueData* Create_Queue();
void init(QueueData* Q);
void enqueue(QueueData** Q, int Value);
int dequeue(QueueData** Q);
void Delete_Queue(QueueData** Q);
void Is_Empty(QueueData** Q);
int printf();

QueueData* Create_Queue()
{
	QueueData* Start = NULL;
	Start = malloc(sizeof(QueueData));
	init(Start);
	return Start;
}

void init(QueueData* Q)
{
	Q->value = NULL;
	Q->NEXT = NULL;
}

void enqueue(QueueData** Q, int Value)
{
	if ((*Q)->value != NULL)
	{
		QueueData* Temp = malloc(sizeof(QueueData));
		init(Temp);

		Temp->value = Value;
		Temp->NEXT = (*Q);
		(*Q) = Temp;
	}
	else
	{
		(*Q)->value = alue;
	}
}

void Print_Queue(QueueData* Q)
{
	QueueData* Temp;
	Temp = Q;

	if (Temp == NULL)
	{
		printf("Queue is empty\n");
	}
	else
	{
		while (Temp != NULL)
		{
			printf("%d ", Temp->value);
			Temp = Temp->NEXT;
		}
		printf("\n ");
	}
}

int dequeue(QueueData** Q)
{
	int returnValue;

	QueueData* Temp = (*Q);
	QueueData* NewTail = (*Q);

	if ((*Q)->NEXT == NULL)
	{
		returnValue = (*Q)->value;
		free((*Q));
		(*Q) = NULL;
	}
	else
	{
		while(Temp->NEXT != NULL)
		{
			NewTail = Temp;
			Temp = Temp->NEXT;
		}
		returnValue = Temp->value;
		free(Temp);

		NewTail->NEXT = NULL;
	}

	return returnValue;
}

void Delete_Queue(QueueData** Q)
{
	QueueData* Temp = *Q;

	while (*Q != NULL)
	{
		QueueData* Temp = (*Q);
		QueueData* NewTail = (*Q);

		if ((*Q)->NEXT == NULL)
		{
			free((*Q));
			(*Q) = NULL;
		}
		else
		{
			while (Temp->NEXT != NULL)
			{
				NewTail = Temp;
				Temp = Temp->NEXT;
			}
			free(Temp);

			NewTail->NEXT = NULL;
		}
	}
}

void is_empty(QueueData** Q)
{
	if ((*Q) == NULL)
		printf("Queue is empty\n");
	else
		printf("Queue is not empty\n");
}

void dijkstra(Typedef_Graph graph, int from, int to)
{
	int i = 0;

	enqueue(from);
	Typedef_Graph g = graph;

	while (!is_empty())
	{
		from = dequeue();

		for (; g.Adj_List[from]; g.Adj_List[from] = g.Adj_List[from]->next)
		{
			if (Distance[g.Adj_List[from]->vertex] 
					> g.Adj_List[from]->distance + Distance[from])
			{
				Distance[g.Adj_List[from]->vertex] =
					g.Adj_List[from]->distance + Distance[from];
			
				path[g.Adj_List[from]->vertex] = from;
				enqueue(g.Adj_List[from]->vertex);
			}
		}
	}
}

void SearchPath(int from, int to)
{
	int vertex = to;
	int stack[MAX_NODE];
	int Top = 0;

	stack[Top++] = vertex;

	while (1)
	{
		vertex = path[vertex];
		stack[Top++] = vertex;
		if (vertex == from) break;
	}

	printf("2. %-15s: ", "P A T H");
	while (--Top >= 0) {
		printf("\[%s]\ ", city[stack[Top]]);
		if (Top > 0) { printf("->"); }
	}
	printf("\n\n");
}

class LatLong {
public:
	double latitude = 0;
	double longitude = 0;

	LatLong(double _lat, double _long) {
		latitude = _lat;
		longitude = _long;
	}
};

int main()
{
	Typedef_Graph graph;
	int i;

	for (i = 0; i < MAX_NODE; i++, graph.Adj_List[i - 1] = NULL);

	AppendNode(&graph, 1, 0, 16.7);
	AppendNode(&graph, 2, 0, 16.77);
	AppendNode(&graph, 2, 1, 15.67);
	AppendNode(&graph, 3, 2, 18.99);
	AppendNode(&graph, 4, 3, 14.56);
	AppendNode(&graph, 4, 5, 15.59);
	AppendNode(&graph, 5, 3, 13.37);
	AppendNode(&graph, 5, 6, 17.79);
	AppendNode(&graph, 5, 7, 17.03);
	AppendNode(&graph, 6, 7, 14.48);
	AppendNode(&graph, 7, 0, 17.81);
					.
                    .
                    .
    AppendNode(&graph, 98, 99. 62.13);
    AppendNode(&graph, 98, 100, 59.02);
    
	DisplayGraph(graph);

	ShortestPath(graph, 4, 0);

	return 0;
}

πŸ“Œ κ²°κ³Ό 및 효과

μœ ν˜• νš¨κ³Όμ™€ λ¬΄ν˜• 효과둜 λ‚˜λˆŒ 수 μžˆλ‹€. λ¨Όμ € μœ ν˜• νš¨κ³ΌλŠ” λͺ…ν™•ν•œ κΈˆμ „μ  이읡으둜 ν™˜μ‚°λ˜λŠ” 효과λ₯Ό λœ»ν•˜κ³  λ¬΄ν˜• νš¨κ³ΌλŠ” 이와 λ°˜λŒ€λ‘œ 잠재적인 이읡이 λ˜λŠ” 당뢄간은 λΉ„κΈˆμ „μ μΈ ν‘œκ³Όλ₯Ό λ§ν•œλ‹€.

3-1. μœ ν˜• 효과

Β· μ“°λ ˆκΈ° 처리 μ‹œκ°„ 단좕

μ“°λ ˆκΈ°λ₯Ό 직접 μˆ˜κ±°ν•˜λŠ” 것이 μ•„λ‹Œ μ΅œλ‹¨ 경둜λ₯Ό 톡해 κ°€κΈ° λ•Œλ¬Έμ— 직접 μˆ˜κ±°ν•˜λŠ” 것보닀 λ‚­λΉ„λ˜λŠ” 처리 μ‹œκ°„μ„ 단좕할 수 μžˆλ‹€.

Β· 원가 절감

μ‹œκ°„μ΄ 단좕됨에 따라 λΉ„μš©λ„ 같이 λ‹¨μΆ•λ˜λŠ” νš¨κ³Όκ°€ μžˆλ‹€.

Β· λΉ„μ¦ˆλ‹ˆμŠ€ 효과

ν˜„μž¬ λ„λ΄‰κ΅¬μ—μ„œ 인곡지λŠ₯ 폐기물을 μ„ λ³„ν•˜λŠ” λ‘œλ΄‡μ„ μ‚¬μš©ν•˜κ³  μžˆλ‹€. μ΅œλ‹¨κ²½λ‘œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ“°λ ˆκΈ°λ₯Ό μ²˜λ¦¬ν•˜λŠ” 것과 κΈ°μˆ μ„ ν•©μΉ˜λ©΄ 더 쒋은 결과물을 톡해 λΉ„μŠ€λ‹ˆμŠ€ 효과λ₯Ό 얻을 수 μžˆλ‹€.

3-2. λ¬΄ν˜• 효과

Β· 기술적 κ²½μŸμš°μœ„

'ν•˜μ²œ μ“°λ ˆκΈ° 처리'의 λ¬Έμ œμ μ— λŒ€ν•΄ λ‹€λ£¨λŠ” κ²½μš°κ°€ 적닀. ν”„λ‘œμ νŠΈμ˜ 결과물을 톡해 κΈ°μˆ μ— λŒ€ν•œ 경쟁λ ₯이 생긴닀.

·지적 μžμ‚° ν™œμš©λΉˆλ„ μ¦λŒ€

λ¬΄ν˜•μ μΈ κ²ƒμœΌλ‘œμ„œ μž¬μ‚°μ  κ°€μΉ˜κ°€ μ‹€ν˜„λ  수 μžˆλŠ” μ§€μ μ°½μž‘λ¬Όμ— λΆ€μ—¬λœ μž¬μ‚°μ— λŒ€ν•œ ꢌ리λ₯Ό λ§ν•œλ‹€. μƒˆλ‘œμš΄ κΈ°μˆ μ„ μ‚¬μš©ν•˜μ—¬ ν™œμš©ν•˜λŠ” νšŸμˆ˜κ°€ λŠ˜μ–΄λ‚œλ‹€.

Β· κ°œμ„  ν™œλ™ μ‹œμŠ€ν…œ ꡬ좕

μ“°λ ˆκΈ°λ₯Ό ν•œλ²ˆμ— μ²˜λ¦¬ν•˜κΈ° νž˜λ“€λ‹€λŠ” 문제점이 μžˆμ„ λ•Œ μ‹œμŠ€ν…œμ„ κ΅¬μΆ•ν•˜λ©΄ 문제 해결에 도움이 λœλ‹€.

profile
Why works? Why doesn't works?

0개의 λŒ“κΈ€