Amaliy ish Bajardi: Akramov Ulug`bek Tekshirdi: Djangazova K. A toshkent 2022


Download 0.7 Mb.
Sana28.12.2022
Hajmi0.7 Mb.
#1022245
Bog'liq
algorit


OʻZBEKISTON RESPUBLIKASI AXBOROT


TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Ma`lumotlat Tuzilmasi va Algoritimlash

3-Amaliy ish




Bajardi: Akramov Ulug`bek
Tekshirdi: Djangazova K. A


Toshkent 2022
Ma`lumotlat Tuzilmasi va Algoritimlash
3-Amaliy ish

1 Berilgan binar daraxtning har bir tuguni chap tomoni tugunlaridan tashkil topgan muvozanatlangan binar daraxt hosil qilish algoritmi va dasturini tuzing.


#include


using namespace std;

struct Node {


int data;
struct Node *left, *right;
};

struct Node* newNode(int item)


{
struct Node* temp
= (struct Node*)malloc(sizeof(struct Node));
temp->data = item;
temp->left = temp->right = NULL;
return temp;
}

void leftViewUtil(struct Node* root, int level,int* max_level)


{
if (root == NULL)


return;

if (*max_level < level) {


cout << root->data << " ";
*max_level = level;
}

leftViewUtil(root->left, level + 1, max_level);


leftViewUtil(root->right, level + 1, max_level);
}

void leftView(struct Node* root)


{
int max_level = 0;
leftViewUtil(root, 1, &max_level);}

int main()


{
Node* root = newNode(10);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(7);
root->left->right = newNode(8);
root->right->right = newNode(15);
root->right->left = newNode(12);
root->right->right->left = newNode(14);

leftView(root);


return 0;


}

2 Qo'shni matritsadan qirralarning ro'yxatini tuzadigan funktsiyani tavsiflang.
#include
using namespace std;

void addEdge(vector adj[], int s, int d) {


adj[s].push_back(d);
adj[d].push_back(s);
}

void printGraph(vector adj[], int V) {


for (int d = 0; d < V; ++d) {
cout << "\n Vertex "
<< d << ":";
for (auto x : adj[d])
cout << "-> " << x;
printf("\n");
}
}

int main() {


int V = 5;

vector adj[V];


// Add edges


addEdge(adj, 0, 1);
addEdge(adj, 0, 2);
addEdge(adj, 0, 3);
addEdge(adj, 1, 2);
printGraph(adj, V);
}

Download 0.7 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling