0% found this document useful (0 votes)
11 views3 pages

Graph Matrix Operations in Pascal

The document is a Pascal program that implements graph operations, including displaying an adjacency matrix, checking graph connectivity, and calculating path lengths between vertices. It features procedures for matrix manipulation and user interaction to input dimensions and vertices. The program allows users to choose different operations related to graph analysis through a menu-driven interface.

Uploaded by

lato
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Graph Matrix Operations in Pascal

The document is a Pascal program that implements graph operations, including displaying an adjacency matrix, checking graph connectivity, and calculating path lengths between vertices. It features procedures for matrix manipulation and user interaction to input dimensions and vertices. The program allows users to choose different operations related to graph analysis through a menu-driven interface.

Uploaded by

lato
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Program graphe ;

Uses crt ;

Var

MAT : array [1..N,1..N] of integer ;


**********Procedur qui affiche ******************************
Proucdure affiche_ MAT(a : matrice ; dimension : integer) ;
Var
I ,j : integer ;
Begin
Writeln (‘affichage de la matrice :’) ;
For i := 1 to demension do
Begin
Write (a [i,j] :8) ;
End ;
Writeln(‘ ‘) ;
End ;
{**** procedure adjacance **************}
Function comparer (n : integer ; a,b : matrice) : boolean ;
Var
Rep : boolean ;
i, j : integer ;
begin
rep := true ;
i := 1 ;
while (i<= n ) and (rep = true) do
begin
j :=1 ;
While (j <= n) and (rep = true) do
Begin
If a [ i,j] <> b [i,j] then rep := false
Else j := j+ 1 ;
End ;

i := i+1 ;
end ;
If rep = true then
Comparer := true
Else
Comparer := false ;
End ;
{********prucedure de la longueur du chemin***************}
Prucedure traitement _longueur ;
Var
b,c,a : matrice ;
d1, d2 , x, s1 ,s2 ,q , dimension : integer ;
Choix : char ;
k : boolean ;
Begin {**** program principale *****************}
Repeat
Case choix of
‘1’ : begin {*** le choix n° 1***}
Clrscr ;
Write (‘dimension de la matrice D’ ‘ adjacence : ‘) ;
Repeat
Readln (dimension) ;
If (dimension >25) then
Writeln (‘la dimension de la matrice doit etre entre 1 et 25’) ;
Until (dimension <= 25 ) ;
Lecteur _ matrice (dimonsion, a) ;
Affict _ matrice (a, dimension, b ) ;
Writeln (‘ la matrice D’ ‘ adjacence est cree !! ‘) ;
Affiche _ matrice (b , dimension ) ;
End ;
‘2’ : begin {*** choix n° 2 *****}
Clrscr ;
K := test_ graphe (b, dimension) ;
If (k = false) then
Begin
Write (‘ remarque : ‘) ;
Writeln (‘ le graphe N ‘ ‘ est pas connexe !! ‘ ) ;
End
Else
Begin
Write (‘ remarque : ‘ ) ;
Writeln (‘ le graphe est connexe !! ‘) ;
End ;
Repeat
Write (‘ donner un sommet ‘x’ : ‘) ;
Readln (x) ;
If (x> dimension) then
Writeln (‘le sommet doit etre entre 1 et ‘ ,dimension’) ;
Until (x <= dimension ) ;
If ( k= true)then
Begin
d1 := degrés _ inter (b ,x, dimension) ;
Writeln (‘le degre interieur de ( ‘, x , ‘ ) est : ‘ , d1 ) ;
d2 := degres _ exter (b,x , dimension) ;
Writeln (‘le degre exterieur de ( ‘, x, ‘ ) est : ‘ , d2 ) ;
End
Else
Begin
d1 := degres_ inter (b, x, dimension) ;
Writeln (‘le degre de (‘,x, ‘ ) est : ‘ , d1) ;
End ;
End ;
‘3’ : begin {**** choix n°3 ****}
Clrscr ;
Repeat
Write (‘ entere la longueur du chemin : ‘) ;
Readln (q ) ;
Affect _ matrice (b, dimension, a ) ;
For i :=1 to q – 1 do
Begin
Write (‘ donner le sommet s1 : ‘) ;
Readln ( s1 ) ;
If (s1 > dimension) then
Writeln (‘ le sommet s1 doit etre entre 1 et ‘ ; dimension, ‘ !! ‘ ) ;
Until ( s1 <= dimension ) ;
Repeat
Write (‘ donner le sommet s2 : ‘) ;
Readln ( s2 ) ;
If ( s2 > dimension )then
Writeln (‘le sommet s2 doit etre entr 1 est ‘ , dimension , ‘ !!’) ;
Until ( s2 <= dimension ) ;
Writeln (‘le nombre de chemin de longueur ‘ , ‘ | ‘ , q , ‘ | ‘ , ‘ entre ‘ , ‘ ‘ , s1 , ‘ ‘ , ‘ et ‘ , ‘
‘ , s2 , ‘ est : ‘ , a [s1 , s2 ] , ‘ chemin (s ) ‘ ) ;
End ;
End ;
{****************** program principal ******************}
Var
Choix : char ;
Begin
Repeat
Readln (choix) ;
Case choix of
‘1’ : traitement longueur ;
‘2’ : connexe ;
‘3 ‘ : longueur entre s1 et s2 ;
End ;
Until (choix = ‘3 ‘ );
END.

You might also like