SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
5.통신망에서 길 찾기


                 과 제         수 행         일 지

                                                         A0 조
                                                             조원
                                                   20063532 조부관
                                                   20073547 홍진욱
                                                   20083438 김무경
                                                   20093447 김도형
                                                   20093489 송하윤
                                                   20093516 장진승


         과제 수행기간 : 5월 14일 ~ 5월 25일 (12일) 총 9시간.


주제 : Directed graph

목표 :   adjacent matrix가 주어졌을 때 indegree/outdegree를 출력하고 source/sink
를 구별하는 프로그램을 만든다.


계획.

첫 주(5월 14일~19일)
 알고리즘을 정리
 익혀야 할 개념에 관하여 연구




둘째주(5월 20~23일)
 전 주에 끝내지 못한 부분을 논의
 과제의 프로그램 소스를 작성 및 완성
첫 주.

5월 14일 월요일

임무분담
조장 : 장진승 자료조사 : 김무경, 김도형, 송하윤 프로그램코딩 : 조부관, 홍진
욱


학습할 내용
directed graph
화살표로 방향을 나타내는데, 그래프를 나타내는 각 모서리에 방향이 있다. 특히 가지가
절점 T1에서 T2로 향하는 방향이 될 때 T1을 시작점, T2를 종점이라 하여 구별한다.
방향이 있으므로 한 방향으로만 갈 수 있다. 이 때 1에서 2로 가는 간선을 <1, 2>로
나타내며, 이것은 <2, 1>과 방향이 다르므로 같지 않다.




precedes, antecedent
선행사건.

indegree, outdegree
방향성 그래프에서 한 정점이 헤드로 구성된 선분의 수를 그 정점의 진입
차수(indegree)라 한다.
방향 그래프의 한 정점에 대해 그 정점에서 다른 정점으로 향하는 간선의 수.

source, sink
indegree에서 보내는 값만 있는것 : source
outdegree에서 받는 값만 있는것 : sink
adjacency matrix
      각 vertex들간의 연결을 행렬로 표현한 것이다. 인접 행렬 M은 n x n 정방행렬로서
      n은 그래프내의 vertex수이다. 행렬의 (i,j)원소 Aij가 1이면 vertex Vi와 Vj가 인접해
      있는 것이고, Aij가 0이면 Vi와 Vj는 인접하지 않은 것이다.
Sample graph       Adjancency matrix for the sample
           인접 행렬의 문제점

          인접 행렬로는 n(n-1)개의 edge를 표현할 수 있다. 그러나 실제로 그래프내의
          edge수는 이보다 훨씬 적기 때문에 대부분의 행렬원소는 0의 값을 가진다. 따라서
          완전 그래프처럼 edge가 많은 경우를 제외하고는 상당량의 기억장소가 낭비되는
          문제가 있다. 이러한 문제를 해결하기 위해 인접 리스트를 사용한다.
          [출처] 그래프(Graph)|작성자 사랑지기


path, length
그래프 G의 정점들의 순서를 경로(path)라고 하며, 경로상의 연결선의 수를 경로의
길이(length)라고 한다.

reachability matrix
                              *                *       *
E에 대한 인접 행렬이 A이고 E 에 대한 인접 행렬이 A 일 때 A 은 아래 식으로 계산되며
이를 G에 대한 도달행렬이라고 한다.
 *=   2    3      n
A A+A +A ...+A

weighted digraph
간선에 비용이나 가중치가 할당된 그래프

weight of a path
경로의 가중치

shortest path
방향 그래프 G=(V,E)에서 n개의 정점이 존재하고 연결선에 가중치(weight)가 주어졌을 때
시작 정점 Vi에서 종착 정점 Vj에 도달하는 여러 경로 중에서 가장 짧은 경로 즉, 가중치의
합이 최소인 경로를 최단 경로(shortest path)라고 한다. 이러한 최단 경로를 구하는 문제
는 Dijkstra의 알고리즘에 기초한다
둘째주.

5월 20일 일요일

초안.
#include <stdio.h>


/*
* define struct 'node'
*/
typedef struct{
char node;
char pair;
int indegree;
int outdegree;
}_node;
/*
* using function
*/
void _nodeSet(_node *node, char tempArr[]);
void _nodeInit(_node nd[],int index);
void charSet(char charArr[],char tempArr[]);


/*
* 처음 charArr가 고정값이기 때문에 index 값도 고정으로 4를 입력해줘야
* 프로그램이 돌아감.
* 입력과 출력은 알아서 바꾸도록.
*/
int main(){
/*
* used value
*/
int index;
/*
* input data change plz
*/
char charArr[]={'A','B','B','D','C','B','D','C','n'};
/*
* temp Array
*/
char tempArr[2];
/*
* input data size
*/
scanf("%d",&index);
/*
* _node struct set
*/
_node nd[index];
_node *node;
node = nd;


/*
* init Struct
*/
_nodeInit(nd,index);



int i;
for(i=0;i<index;i++){
//scanf("%s",tempArr);
/*
* degree operation.
*/
charSet(charArr,tempArr);
_nodeSet(node,tempArr);


}
/*
* print sturct
*/
for(i=0;i<index;i++){
printf("node = %cn",(node+i)->node);
printf("pair = %cn",(node+i)->pair);
printf("inde = %dn",(node+i)->indegree);
printf("outd = %dnn",(node+i)->outdegree);
}
getch();
}
/*
* 그냥 처음 노드 순서쌍 구한다음에 배열 당기는 함수.
*/
void charSet(char charArr[],char tempArr[]){
tempArr[0] = charArr[0];
tempArr[1] = charArr[1];


int i;
char temp;
for(i=2;charArr[i] != 'n' ; i++){
charArr[i-2] = charArr[i];
}
}
/*
* 노드 스트럭트 초기화.
*/
void _nodeInit(_node nd[],int index){
int i;
for(i=0;i<index;i++){


(nd+i)->node = '0';
(nd+i)->pair = '0';
(nd+i)->indegree = 0;
(nd+i)->outdegree = 0;
}


}
/*
* 예로 AB 면 앞에 있는 A 구조체에 접근한다음에 outdegree 증가시켜주고
* 뒤에있는 B 구조체에 접근에서 indegree 증가시켜주는 함수.
*/
void _nodeSet(_node *node, char tempArr[]){
(node+((int)tempArr[0]-65))->node = tempArr[0];
(node+((int)tempArr[0]-65))->pair = tempArr[1];
(node+((int)tempArr[0]-65))->outdegree++;
(node+((int)tempArr[1]-65))->indegree++;
}
5월 23일 수요일

최종 소스.
#include <stdio.h>


/*
*    define struct 'node'
*/
typedef struct{
     char     node;
     char     pair;
     int      indegree;
     int      outdegree;
}_node;
/*
*    using function
*/
void _nodeSet(_node *node, char tempArr[]);
void _nodeInit(_node nd[],int index);
void charSet(char charArr[],char tempArr[]);


/*
*    node 개수만큼 숫자를 입력해줘야
*    프로그램이 돌아감.
*/
int main(){
/*
*    used value
*/
     int      index;
/*
*    input data change plz
*/


//    char      charArr[100]={'A','B','B','D','C','B','D','C','n'};
     char charArr[100];//걸러낸거 들어오는곳
     char Arr[100];//우선 입력 받는곳
     int next=0;
     int j;
for(j=0;j<100;j++)
     Arr[j]='n';
/*
*    temp Array
*/
     char     tempArr[2];
/*
*    input data size
*/
     scanf("%dn",&index);//node 수 입력 (ex: 4)
     int ct=0;
          gets(Arr);// 관계 입력(ex: AB, BD, CB, DC) 이런식으로 쭉 입력후 엔터(공백
포함 상관 없음)


     for(j=0;j<100;j++)// 문자 걸러내기 부분
     {
      if((Arr[j]>=65&&Arr[j]<=90)||Arr[j]=='n')
      {
      charArr[next]=Arr[j];
      next++;
      }
     }
/*   안에 잘 들어있는지 확인 (마지막 쓰레기값은 상관 없음.
     for(j=0;j<100;j++)
     printf("%c",charArr[j]);
*/


/*
*    _node struct set
*/
     _node nd[index];
     _node *node;
     node = nd;


     /*
     *    init Struct
     */
     _nodeInit(nd,index);
int        i;
     for(i=0;i<index;i++){
           //scanf("%s",tempArr);
/*
*    degree operation.
*/
           charSet(charArr,tempArr);
           _nodeSet(node,tempArr);


     }
/*
*    print sturct
*/
     for(i=0;i<index;i++){
           printf("%-2c",(node+i)->node);
           printf("%-2d",(node+i)->indegree);//INDEGREE
           printf("%-2d",(node+i)->outdegree);//OUTDEGREE
           if(((node+i)->indegree)==0)
           printf("source");


           if(((node+i)->outdegree)==0)
           printf("sink");


           printf("nn");
//          printf("pair = %cnn",(node+i)->pair);



     }


     getch();
}
/*
*    그냥 처음 노드 순서쌍 구한다음에 배열 당기는 함수.
*/
void charSet(char charArr[],char tempArr[]){
     tempArr[0] = charArr[0];
     tempArr[1] = charArr[1];


     int        i;
     char temp;
for(i=2;charArr[i] != 'n' ; i++){
           charArr[i-2] = charArr[i];
     }
}
/*
*    노드 스트럭트 초기화.
*/
void _nodeInit(_node nd[],int index){
     int      i;
     for(i=0;i<index;i++){


           (nd+i)->node =      'A'+i;
           (nd+i)->pair =    '0';
           (nd+i)->indegree =       0;
           (nd+i)->outdegree        =    0;
     }


}


/*
*    예로 AB 면 앞에 있는 A 구조체에 접근한다음에 outdegree 증가시켜주고
*    뒤에있는 B 구조체에 접근에서 indegree 증가시켜주는 함수.
*/
void _nodeSet(_node *node, char tempArr[]){
     (node+((int)tempArr[0]-65))->node = tempArr[0];
     (node+((int)tempArr[0]-65))->pair = tempArr[1];
     (node+((int)tempArr[0]-65))->outdegree++;
     (node+((int)tempArr[1]-65))->indegree++;


}
결과.

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

2012 Dm A0 05 Pdf

  • 1. 5.통신망에서 길 찾기 과 제 수 행 일 지 A0 조 조원 20063532 조부관 20073547 홍진욱 20083438 김무경 20093447 김도형 20093489 송하윤 20093516 장진승 과제 수행기간 : 5월 14일 ~ 5월 25일 (12일) 총 9시간. 주제 : Directed graph 목표 : adjacent matrix가 주어졌을 때 indegree/outdegree를 출력하고 source/sink 를 구별하는 프로그램을 만든다. 계획. 첫 주(5월 14일~19일) 알고리즘을 정리 익혀야 할 개념에 관하여 연구 둘째주(5월 20~23일) 전 주에 끝내지 못한 부분을 논의 과제의 프로그램 소스를 작성 및 완성
  • 2. 첫 주. 5월 14일 월요일 임무분담 조장 : 장진승 자료조사 : 김무경, 김도형, 송하윤 프로그램코딩 : 조부관, 홍진 욱 학습할 내용 directed graph 화살표로 방향을 나타내는데, 그래프를 나타내는 각 모서리에 방향이 있다. 특히 가지가 절점 T1에서 T2로 향하는 방향이 될 때 T1을 시작점, T2를 종점이라 하여 구별한다. 방향이 있으므로 한 방향으로만 갈 수 있다. 이 때 1에서 2로 가는 간선을 <1, 2>로 나타내며, 이것은 <2, 1>과 방향이 다르므로 같지 않다. precedes, antecedent 선행사건. indegree, outdegree 방향성 그래프에서 한 정점이 헤드로 구성된 선분의 수를 그 정점의 진입 차수(indegree)라 한다. 방향 그래프의 한 정점에 대해 그 정점에서 다른 정점으로 향하는 간선의 수. source, sink indegree에서 보내는 값만 있는것 : source outdegree에서 받는 값만 있는것 : sink adjacency matrix 각 vertex들간의 연결을 행렬로 표현한 것이다. 인접 행렬 M은 n x n 정방행렬로서 n은 그래프내의 vertex수이다. 행렬의 (i,j)원소 Aij가 1이면 vertex Vi와 Vj가 인접해 있는 것이고, Aij가 0이면 Vi와 Vj는 인접하지 않은 것이다.
  • 3. Sample graph Adjancency matrix for the sample 인접 행렬의 문제점 인접 행렬로는 n(n-1)개의 edge를 표현할 수 있다. 그러나 실제로 그래프내의 edge수는 이보다 훨씬 적기 때문에 대부분의 행렬원소는 0의 값을 가진다. 따라서 완전 그래프처럼 edge가 많은 경우를 제외하고는 상당량의 기억장소가 낭비되는 문제가 있다. 이러한 문제를 해결하기 위해 인접 리스트를 사용한다. [출처] 그래프(Graph)|작성자 사랑지기 path, length 그래프 G의 정점들의 순서를 경로(path)라고 하며, 경로상의 연결선의 수를 경로의 길이(length)라고 한다. reachability matrix * * * E에 대한 인접 행렬이 A이고 E 에 대한 인접 행렬이 A 일 때 A 은 아래 식으로 계산되며 이를 G에 대한 도달행렬이라고 한다. *= 2 3 n A A+A +A ...+A weighted digraph 간선에 비용이나 가중치가 할당된 그래프 weight of a path 경로의 가중치 shortest path 방향 그래프 G=(V,E)에서 n개의 정점이 존재하고 연결선에 가중치(weight)가 주어졌을 때 시작 정점 Vi에서 종착 정점 Vj에 도달하는 여러 경로 중에서 가장 짧은 경로 즉, 가중치의 합이 최소인 경로를 최단 경로(shortest path)라고 한다. 이러한 최단 경로를 구하는 문제 는 Dijkstra의 알고리즘에 기초한다
  • 4. 둘째주. 5월 20일 일요일 초안. #include <stdio.h> /* * define struct 'node' */ typedef struct{ char node; char pair; int indegree; int outdegree; }_node; /* * using function */ void _nodeSet(_node *node, char tempArr[]); void _nodeInit(_node nd[],int index); void charSet(char charArr[],char tempArr[]); /* * 처음 charArr가 고정값이기 때문에 index 값도 고정으로 4를 입력해줘야 * 프로그램이 돌아감. * 입력과 출력은 알아서 바꾸도록. */ int main(){ /* * used value */ int index; /* * input data change plz */ char charArr[]={'A','B','B','D','C','B','D','C','n'};
  • 5. /* * temp Array */ char tempArr[2]; /* * input data size */ scanf("%d",&index); /* * _node struct set */ _node nd[index]; _node *node; node = nd; /* * init Struct */ _nodeInit(nd,index); int i; for(i=0;i<index;i++){ //scanf("%s",tempArr); /* * degree operation. */ charSet(charArr,tempArr); _nodeSet(node,tempArr); } /* * print sturct */ for(i=0;i<index;i++){ printf("node = %cn",(node+i)->node); printf("pair = %cn",(node+i)->pair); printf("inde = %dn",(node+i)->indegree); printf("outd = %dnn",(node+i)->outdegree); }
  • 6. getch(); } /* * 그냥 처음 노드 순서쌍 구한다음에 배열 당기는 함수. */ void charSet(char charArr[],char tempArr[]){ tempArr[0] = charArr[0]; tempArr[1] = charArr[1]; int i; char temp; for(i=2;charArr[i] != 'n' ; i++){ charArr[i-2] = charArr[i]; } } /* * 노드 스트럭트 초기화. */ void _nodeInit(_node nd[],int index){ int i; for(i=0;i<index;i++){ (nd+i)->node = '0'; (nd+i)->pair = '0'; (nd+i)->indegree = 0; (nd+i)->outdegree = 0; } } /* * 예로 AB 면 앞에 있는 A 구조체에 접근한다음에 outdegree 증가시켜주고 * 뒤에있는 B 구조체에 접근에서 indegree 증가시켜주는 함수. */ void _nodeSet(_node *node, char tempArr[]){ (node+((int)tempArr[0]-65))->node = tempArr[0]; (node+((int)tempArr[0]-65))->pair = tempArr[1]; (node+((int)tempArr[0]-65))->outdegree++; (node+((int)tempArr[1]-65))->indegree++; }
  • 7. 5월 23일 수요일 최종 소스. #include <stdio.h> /* * define struct 'node' */ typedef struct{ char node; char pair; int indegree; int outdegree; }_node; /* * using function */ void _nodeSet(_node *node, char tempArr[]); void _nodeInit(_node nd[],int index); void charSet(char charArr[],char tempArr[]); /* * node 개수만큼 숫자를 입력해줘야 * 프로그램이 돌아감. */ int main(){ /* * used value */ int index; /* * input data change plz */ // char charArr[100]={'A','B','B','D','C','B','D','C','n'}; char charArr[100];//걸러낸거 들어오는곳 char Arr[100];//우선 입력 받는곳 int next=0; int j;
  • 8. for(j=0;j<100;j++) Arr[j]='n'; /* * temp Array */ char tempArr[2]; /* * input data size */ scanf("%dn",&index);//node 수 입력 (ex: 4) int ct=0; gets(Arr);// 관계 입력(ex: AB, BD, CB, DC) 이런식으로 쭉 입력후 엔터(공백 포함 상관 없음) for(j=0;j<100;j++)// 문자 걸러내기 부분 { if((Arr[j]>=65&&Arr[j]<=90)||Arr[j]=='n') { charArr[next]=Arr[j]; next++; } } /* 안에 잘 들어있는지 확인 (마지막 쓰레기값은 상관 없음. for(j=0;j<100;j++) printf("%c",charArr[j]); */ /* * _node struct set */ _node nd[index]; _node *node; node = nd; /* * init Struct */ _nodeInit(nd,index);
  • 9. int i; for(i=0;i<index;i++){ //scanf("%s",tempArr); /* * degree operation. */ charSet(charArr,tempArr); _nodeSet(node,tempArr); } /* * print sturct */ for(i=0;i<index;i++){ printf("%-2c",(node+i)->node); printf("%-2d",(node+i)->indegree);//INDEGREE printf("%-2d",(node+i)->outdegree);//OUTDEGREE if(((node+i)->indegree)==0) printf("source"); if(((node+i)->outdegree)==0) printf("sink"); printf("nn"); // printf("pair = %cnn",(node+i)->pair); } getch(); } /* * 그냥 처음 노드 순서쌍 구한다음에 배열 당기는 함수. */ void charSet(char charArr[],char tempArr[]){ tempArr[0] = charArr[0]; tempArr[1] = charArr[1]; int i; char temp;
  • 10. for(i=2;charArr[i] != 'n' ; i++){ charArr[i-2] = charArr[i]; } } /* * 노드 스트럭트 초기화. */ void _nodeInit(_node nd[],int index){ int i; for(i=0;i<index;i++){ (nd+i)->node = 'A'+i; (nd+i)->pair = '0'; (nd+i)->indegree = 0; (nd+i)->outdegree = 0; } } /* * 예로 AB 면 앞에 있는 A 구조체에 접근한다음에 outdegree 증가시켜주고 * 뒤에있는 B 구조체에 접근에서 indegree 증가시켜주는 함수. */ void _nodeSet(_node *node, char tempArr[]){ (node+((int)tempArr[0]-65))->node = tempArr[0]; (node+((int)tempArr[0]-65))->pair = tempArr[1]; (node+((int)tempArr[0]-65))->outdegree++; (node+((int)tempArr[1]-65))->indegree++; } 결과.