Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
//Task 2.
#include <stdio.h>
#include <malloc.h>
#define N 9
typedef enum {white, gray, black} Color;
typedef enum {FALSE, TRUE} bool;
typedef struct vertex {
char name;
Color clr;
struct vertex* pred; // index of previous vertex in the traversal
bool critical; //
bool hidden;
struct vertex* adjacent[N];//adjacent vertex as per DFS
int time;
} Vertex;
int Adj[N][N] = {
/*S B C D E F G H T */
{0, 1, 1, 0, 0, 0, 0, 0, 0}, // S
{1, 0, 0, 1, 1, 0, 0, 0, 0}, // B
{1, 0, 0, 0, 1, 0, 0, 0, 0}, // C
{0, 1, 0, 0, 0, 1, 0, 0, 0}, // D
{0, 1, 1, 0, 0, 1, 0, 0, 0}, // E
{0, 0, 0, 1, 1, 0, 1, 1, 0}, // F
{0, 0, 0, 0, 0, 1, 0, 1, 1}, // G
{0, 0, 0, 0, 0, 1, 1, 0, 1}, // H
{0, 0, 0, 0, 0, 0, 1, 1, 0}, // T
};
int time = 0; // a global variable to account // adjacency matrix
void initMemory(void){
int i;
for(i = 0; i < N; i++){
V[i]=(Vertex*)malloc(sizeof(Vertex));
}
}
void init(void){
int i;
for(i = 0; i < N; i++){
V[i]->clr = white;
V[i]->pred = NULL;
}
}
void setAdjList(void)//converting the adjacency matrix into adjacent list for DFS
{
int j,i,k;
for(i = 0; i < N; i++)
{ k=0;
for(j = 0; j < N; j++)
{
if(Adj[i][j]==1){
V[i]->adjacent[k]=V[j];
k++;
printf("\n %d , %d , K %d",i , j,k);
}
}V[i]->adjacent[k]=NULL;
}
}
void setName(void)
{
int i;
char names [N+1]="SBCDEFGHT";
for(i = 0; i < N; i++){
V[i]->name=names[i];
}
}
}
}
else
printf(" doesnt exist s-t path\n");
return answer;
}
int main() {
initMemory();
init();
setAdjList();
setName();
if(isUnreliableConnected(*V[0],*V[8])==TRUE){
printf("\n****is Unreliable****");}
else printf("\n*|*|*|* Reliable *|*|*|*");
}