0% found this document useful (0 votes)
44 views2 pages

Parcurgere Arbori Pascal

This document contains code for traversing and creating a binary tree data structure in Pascal. It defines a record to represent nodes with left and right child pointers and integer data. Functions are defined to recursively traverse the tree in inorder, create the tree by prompting for integer values, and find the maximum key in the tree by recursively searching left and right subtrees.

Uploaded by

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

Parcurgere Arbori Pascal

This document contains code for traversing and creating a binary tree data structure in Pascal. It defines a record to represent nodes with left and right child pointers and integer data. Functions are defined to recursively traverse the tree in inorder, create the tree by prompting for integer values, and find the maximum key in the tree by recursively searching left and right subtrees.

Uploaded by

Dan Dumitru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM ARBORI_PARCURSI_CU_LISTE; PROGRAM ARBORI_PARCURSI_CU_LISTE_FCTIE;

TYPE REF=^INR; TYPE REF=^INR;


INR=RECORD INR=RECORD
ST,DR:REF; ST,DR:REF;
NR:INTEGER; NR:INTEGER;
END; END;
VAR C:REF;I,N, RAD:INTEGER; VAR C:REF;I,N, RAD:INTEGER;

PROCEDURE INORD(C:REF); PROCEDURE INORD(C:REF);


BEGIN BEGIN
IF C<>NIL THEN IF C<>NIL THEN
BEGIN BEGIN
INORD(C^.ST); INORD(C^.ST);
WRITE(C^.NR,' '); WRITE(C^.NR,' ');
INORD(C^.DR); INORD(C^.DR);
END; END;
END; END;

PROCEDURE CREARE(VAR C:REF); FUNCTION CREARE(VAR C:REF):REF;


VAR VAL:INTEGER; VAR VAL:INTEGER;
BEGIN BEGIN
WRITE('VAL='); READLN(VAL); WRITE('VAL='); READLN(VAL);
IF (VAL<>0) THEN IF (VAL<>0) THEN
BEGIN BEGIN
NEW(C); NEW(C);
C^.NR:=VAL; C^.NR:=VAL;
WRITE('ST=',VAL); WRITE('ST=',VAL);
CREARE(C^.ST); CREARE(C^.ST);
WRITE('DR=', VAL); WRITE('DR=', VAL);
CREARE(C^.DR); CREARE(C^.DR);
END END
ELSE ELSE
C:=NIL; C:=NIL;
END; END;

BEGIN BEGIN
CREARE(C);
INORD(C); CREARE(C);
END. INORD(C);
END.
PROGRAM CHEIA_MAXIMA_A_UNUI_ARBORE_BINAR;
{SCRIETI O FUNCTIE CARE, PRIMIND CA PARAMETRU UN
POINTER CATRE RADACINA
UNUI ARBORE BINAR DE NUMERE INTREGI, RETURNEAZA
CHEIA MAXIMA DIN ARBORE}
TYPE REF=^INR;
INR=RECORD
NR:INTEGER;
ST,DR:REF;
END;

VAR C:REF; I,N:INTEGER;

FUNCTION CHEIE_MAX(C:REF):INTEGER;
VAR MAX1,MAX2:INTEGER;
BEGIN
IF C^.ST<>NIL THEN MAX1:=CHEIE_MAX(C^.ST)
ELSE
MAX1:=0;
IF C^.DR<>NIL THEN MAX2:=CHEIE_MAX(C^.DR)
ELSE
MAX2:=0;

IF MAX1<MAX2 THEN MAX1:=MAX2;


IF MAX1>C^.NR THEN CHEIE_MAX:=MAX1
ELSE
CHEIE_MAX:=C^.NR;
END;

PROCEDURE INORD(C:REF);
BEGIN
IF C<>NIL THEN
BEGIN
INORD(C^.ST); WRITE(C^.NR,' '); INORD(C^.DR);
END;
END;

FUNCTION CREARE(VAR C:REF):REF;


VAR VAL:INTEGER;
BEGIN
WRITE('VAL='); READLN(VAL);
IF (VAL<>0) THEN
BEGIN
NEW(C);
C^.NR:=VAL; WRITE('ST=',VAL); CREARE(C^.ST);
WRITE('DR=', VAL); CREARE(C^.DR);
END
ELSE
C:=NIL;
END;

BEGIN
CREARE(C);
INORD(C);
WRITE('AF.MAXIMUL=', CHEIE_MAX(C));
END.

You might also like