반응형

인접행렬 9

[C언어 알고리즘] 5.4 인접 행렬로 표현한 그래프 소스 코드

[C언어 알고리즘] 5.4 인접 행렬로 표현한 그래프 소스 코드//Program.c #include #include #include typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 } Graph; Graph *NewGraph(int max_vertex);//그래프 동적 생성 void DeleteGraph(Graph *graph);//그래프 소멸 void AddEdge(Graph *graph, int start, int goal);//간선 추가 void ViewGraph(Graph *graph);//그래프 정보 출력 void ViewIndegree(Graph *g);//진입차수 확인 void ViewOutdegree(Graph *g)..

[C언어 알고리즘] 5.2.1 인접 행렬로 방향성 있는 그래프 소스 코드

[C언어 알고리즘] 5.2.1 인접 행렬로 방향성 있는 그래프 소스 코드//Program.c #include #include #include typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 } Graph; Graph *NewGraph(int max_vertex);//그래프 동적 생성 void DeleteGraph(Graph *graph);//그래프 소멸 void AddEdge(Graph *graph, int start, int goal);//간선 추가 void ViewGraph(Graph *graph);//그래프 정보 출력 int main(void) { Graph *graph; graph = NewGraph(6);//그래프 동적 생..

[C언어 알고리즘] 5.1.1 인접 행렬로 방향성 없는 그래프 소스 코드

[C언어 알고리즘] 5.1.1 인접 행렬로 방향성 없는 그래프 소스 코드//방향성 없는 그래프 #include #include #include typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 }Graph; Graph *MakeGraph();//그래프 만들기 void ViewNeighbors(Graph *g);//이웃 정점 보여주기 void DeleteGraph(Graph *graph);//그래프 소멸 int main(void) { Graph *graph; graph = MakeGraph();//그래프 만들기 ViewNeighbors(graph); //이웃 정점 보여주기 DeleteGRaph(graph);//그래프 소멸 return ..

[C언어 자료구조] 7.6 진입 차수, 진출 차수 소스 코드

7.6 진입 차수, 진출 차수 소스 코드//Program.c #include #include #include typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 } Graph; Graph *NewGraph(int max_vertex);//그래프 동적 생성 void DeleteGraph(Graph *graph);//그래프 소멸 void AddEdge(Graph *graph, int start, int goal);//간선 추가 void ViewGraph(Graph *graph);//그래프 정보 출력 void ViewIndegree(Graph *g);//진입차수 확인 void ViewOutdegree(Graph *g);//진출차수 확인 in..

[C언어 자료구조] 7.4 인접 행렬로 방향성 있는 그래프 소스 코드

7.4 인접 행렬로 방향성 있는 그래프 소스 코드//Program.c #include #include #include typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 } Graph; Graph *NewGraph(int max_vertex);//그래프 동적 생성 void DeleteGraph(Graph *graph);//그래프 소멸 void AddEdge(Graph *graph, int start, int goal);//간선 추가 void ViewGraph(Graph *graph);//그래프 정보 출력 int main(void) { Graph *graph; graph = NewGraph(6);//그래프 동적 생성 AddEdge(gra..

[C언어 자료구조] 7.3 인접 행렬로 방향성 있는그래프

7.3 인접 행렬로 방향성 있는그래프방향성 있는 그래프는 간선의 출발지와 목적지가 정해져 있는 그래프를 말해요. 방향성 있는 그래프를 표현하는 방법 중에 간단한 그래프에는 인접 행렬을 많이 사용해요. 먼저 그래프 형식을 정의하기로 해요. 그래프 형식은 방향성 없는 그래프와 차이가 없어요. 정점의 개수와 인접 행렬을 멤버를 추가하세요. typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 } Graph; 그래프를 생성하고 소멸, 추가, 정보 출력하는 기능을 제공하기로 해요. Graph *NewGraph(int max_vertex);//그래프 동적 생성 void DeleteGraph(Graph *graph);//그래프 소멸 void AddE..

[C언어 자료구조] 7.1 인접 행렬로 방향성 없는그래프

7.1 인접 행렬로 방향성 없는그래프방향성 없는 그래프는 정점 A에서 정점 B로 이동할 수 있으면 언제나 정정 B에서 정정 B로 이동할 수 있음을 보장하는 그래프예요. 방향성 없는 그래프를 표현하는 방법 중에 간단한 그래프에는 인접 행렬을 많이 사용해요. 인접 행렬로 방향성 없는 그래프를 표현하면 좌상단에서 우하단으로 이어지는 대각선에 대칭 형태죠. 먼저 그래프 형식을 정의하기로 해요. 인접 행렬로 그래프를 표현할 때 그래프에는 정점 개수와 인접 행렬이 필요하겠죠. typedef struct{//그래프 형식 정의 int vn; //정점 개수 int **matrix;//그래프 인접 행렬 }Graph; 여기에서는 그래프 생성, 소멸, 간선 추가, 이웃 정점을 보여주는 기능을 제공하기로 해요. Graph *M..

10.3.3 깊이 우선 탐색(인접 행렬) 코드 [디딤돌 자료구조와 알고리즘 with C++]

10.3.3 깊이 우선 탐색(인접 행렬) 코드 다음은 앞에서 작성한 인접 행렬로 구현한 그래프와 이를 이용한 깊이 우선 탐색 소스 코드입니다. 여기에서는 방향성 없는 그래프를 소개할게요. //Graph.h#pragma once#include #include using namespace std;typedef vector Neighbors;class Graph{ const int vn;//정점의 개수 int **matrix;//인접 행렬 public: Graph(int vn); ~Graph(void); void AddEdge(int start, int goal);//간선 추가 void ViewNeighbors()const; void ViewNeighbor(int vt)const; Neighbors FindN..

디딤돌 자료구조와 알고리즘 C++

디딤돌 자료구조와 알고리즘 C++ 책 소개 자료구조는 자료를 메모리에 표현하는 구조를 말하며 크게 선형 자료구조와 비 선형 자료구조로 나눠요. 선형 자료구조에는 같은 종류의 자료를 연속적인 메모리에 관리하는 배열과 데이터와 링크로 구성하는 노드들의 선형 집합인 연결리스트가 있어요. 그리고 임시적으로 자료를 보관하는 버퍼로 가장 최근에 보관한 자료를 꺼내주는 스택(Last In First Out)과 가장 먼저 보관한 자료를 꺼내주는 큐(First In First Out)도 선형 자료구조인 배열이나 연결리스트를 이용한 잘 알려진 버퍼입니다. 비 선형 자료구조에는 나무의 뿌리처럼 자료를 보관하는 모습을 계층적으로 표현할 수 있는 트리와 정점과 간선으로 표현하는 그래프 등이 있어요. 이 책에서는 이러한 자료구조..

반응형