Professional Documents
Culture Documents
Raport
Tema :
“Analiza prelucrării structurilor de date cu liste ”
A efectuat: ,TI-173
Chisinău 2018
1
Cuprins:
2
Scopul şi obiectivele:
1.de studiat şi însuşit materialul teoretic pentru evidenţierea esenţialului prelucrării structurilor
de date cu arbori în elaborarea modelelor soluţiei, anaizând exemplele din text;
3.exemplele din 1.3. (Aplicaţii de arbori binari în C), 2. şi exemplele 2.7 de derulat, obţinând
rezultatele de testare, verificare pentru care să se elaboreze scenariile succinte de soluţionare,
algoritmii funcţiilor principale, organigramele SD şi programele cu arbori şi fişiere (declarări şi
procesări).şi expuse în raport.
3
Sarcina:
Sa se dea la executie un program care prelucreza arborele si de explicat eficienta
arborilor,parcurgerile lui.
#include <stdio.h>
#include <stdlib.h>
/*Function protoypes*/
int getWidth(struct node* root, int level);
int height(struct node* node);
struct node* newNode(int data);
4
/* Get width of each level and compare
the width with maximum width so far */
for(i=1; i<=h; i++)
{
width = getWidth(root, i);
if(width > maxWidth)
maxWidth = width;
}
return maxWidth;
}
if(root == NULL)
return 0;
if(level == 1)
return 1;
/* UTILITY FUNCTIONS */
5
/* Compute the "height" of a tree -- the number of
nodes along the longest path from the root node
down to the farthest leaf node.*/
int height(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the height of each subtree */
int lHeight = height(node->left);
int rHeight = height(node->right);
/* use the larger one */
6
{
struct node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
root->right->left = newNode(9);
root->right->right = newNode(8);
root->right->right->left = newNode(6);
root->right->right->right = newNode(7);
/*
Constructed bunary tree is:
1
/ \
2 3
/ \ \
4 5 8
/ \
6 7
*/
printf("Maximum width of binary tree is %d .\n", getMaxWidth(root));
return 0;
}
7
8