samedi 25 avril 2015

adjacency matrix find if neighbores


I have some homwrok and it looks like this: Question 1 ( First program adjacency.c file ) Directed tree structure T has N nodes represented by the adjacency matrix A size NxN as follows:

A [ u ] [ v] == TRUE if and only if there is a directed arc from u to v in T , or in other words : u is the parent of v . In the following example a tree with N = 11 nodes :

tree

We obtain the following neighboring matrix :

matrix

this are the questions:

A. You must define with #define command and / or enum the N and permanent TRUE and FALSE. Typedef should be set with a character named adj_mat defines the neighboring matrix size N.

B. You must write a function called path, which accepts as a parameter adjacency matrix A and indexes of two nodes u and v and returns TRUE if and only if there is a directed path (by directional arrow) at the intersection u v, the tree is represented by a matrix A. Otherwise it returns FALSE.

For example: path (1,8) will return TRUE. The same path (1,3). On the other hand path (3,8) will FALSE.

C. First you must write a function (main) defines a variable type adj_mat, asks the user entries for this matrix, and indexes of the two nodes. The main function function call path, to see if there is a directed path between two nodes in the data. The function to print the test result output.

have to get some help guys

#include <stdio.h>

#define N 11
enum {FALSE, TRUE};
typedef int adj_mat[N][N];

int path(adj_mat A, int u, int v)
{
if(u == 0 && A[u][v] == TRUE)
return TRUE;

if(u == 0 && A[u][v] == FALSE)
return FALSE;

if(A[u][v] == FALSE)
{
--u;
return path(A, -u, v);
}

else if(A[u][v] == TRUE)
return path(A, N-1, u);
return FALSE;
}

int main()
{

int arr[N][N]= {{0,1,1,1,0,0,0,0,0,0,0},{0,0,0,0,1,1,1,1,1,0,0},
{0,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,0,0,0,1},{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}};
int u;
int v;
printf("please enter two numbers \n");
scanf("%d", &u);
scanf("%d", &v);
return path(arr, u, v);
;
}

The problem is at the terminal when i put 1,8 it doesnt do nothing.


Aucun commentaire:

Enregistrer un commentaire