Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Diskret / Graph_in_deep / main

.cpp
Скачиваний:
5
Добавлен:
18.08.2019
Размер:
1.11 Кб
Скачать
#include "stdafx.h"
#include <iostream>
using namespace std;

const int N = 9;
//матрица смежности графа
//                0 1 2 3 4 5 6 7 8
int Graf[N][N] ={{0,1,0,0,0,5,6,7,0},//0
                 {1,0,1,0,0,0,0,1,0},//1
                 {0,1,0,1,0,0,0,1,1},//2
                 {0,0,1,0,1,0,0,0,1},//3
                 {0,0,0,1,0,1,1,0,1},//4
                 {1,0,0,0,1,0,1,0,0},//5
                 {1,0,0,0,1,1,0,1,1},//6
                 {1,1,1,0,0,0,1,0,1},//7
                 {0,0,1,1,1,0,1,1,0}};//8


void DFS(int st, int n, bool *visited)
{
int r;
cout << st << " ";
visited[st] = true;
for (r=0; r <= n; r++)
if ((Graf[st][r]!=0) && (!visited[r]))
DFS(r,n,visited);
}

int main()
{
int start;
int i, j;
bool *visited=new bool[N];

cout << "The adjacency matrix of a graph: " << endl;
for (i=0; i<N; i++)
{
visited[i] = false;
for (j=0; j<N; j++)
cout<<" " << Graf[i][j];
cout<<endl;
}

cout<<"Input start point: "; cin>>start;
//массив посещенных вершин
cout << "Bypass order: ";

DFS(start,N,visited);

delete []visited;

cin.get();
return 0;
}
Соседние файлы в папке Graph_in_deep
  • #
    18.08.20191.12 Кб5Graph_in_deep.cbp
  • #
    18.08.2019120 б6Graph_in_deep.depend
  • #
    18.08.2019321 б5Graph_in_deep.layout
  • #
    18.08.20191.11 Кб5main.cpp
  • #
    18.08.2019230 б6void