Muhammad al-Xorazmiy Nomidagi Toshkent Axborot Texnologiyalari Universititeti
Download 141.5 Kb.
|
abdugaffor
- Bu sahifa navigatsiya:
- Xulosa Men bu mustaqil ishida binary daraxtlarhaqida, binary daraxtlar ustida amallar bajarishni o’rgandim. Foydalanilgan adabiyotlar
type chr_tree = Empty | Node of char * chr_tree * chr_tree
Massivlar Ikkilik daraxtlar, shuningdek, kenglikdagi ma'lumotlarning yopiq tuzilishi shaklida kenglikda saqlanishi mumkin va agar daraxt to'liq ikkilik daraxt bo'lsa, bu usul bo'sh joy qoldirmaydi. Agar tugun i indeksiga ega bo'lsa, uning kichik elementlari {\displaystyle 2i+1}2i+1 (chap bola uchun) va {\displaystyle 2i+2}2i+2 (o'ng uchun) indeksida bo'lsa,uning ota-onasi (agar mavjud bo'lsa) {\displaystyle \left\lfloor {\frac {i-1}{2}\right\rfloor} \left\lfloor {\frac {i-1} {2}\right\rfloor (ildiz nol indeks bor taqdim). Shu bilan bir qatorda, 1-indeks qator bilan, amalga oshirish {\displaystyle 2i}2i va {\displaystyle 2i+1}2i + 1 topilgan bolalar bilan soddalashtirilgan va ota-ona da topilgan {\displaystyle \lfloor i / 2 \ rfloor } {\displaystyle \ lfloor i / 2 \ rfloor }. [28] ushbu usul,ayniqsa, oldindan buyurtma berish vaqtida, yanada ixcham saqlash va yaxshi mos yozuvlar joyidan foydalidir. Misollar // C++ program to insert element in Binary Tree #include #include using namespace std; /* A binary tree node has data, pointer to left child and a pointer to right child */ struct Node { int data; Node* left; Node* right; }; /* Function to create a new node */ Node* CreateNode(int data)
/* Function to insert element in binary tree */ Node* InsertNode(Node* root, int data)
// Else, do level order traversal until we find an empty // place, i.e. either left child or right child of some // node is pointing to NULL. queue q.push(root); while (!q.empty()) { Node* temp = q.front(); q.pop(); if (temp->left != NULL) q.push(temp->left); else { temp->left = CreateNode(data); return root; } if (temp->right != NULL) q.push(temp->right); else { temp->right = CreateNode(data); return root; } } } /* Inorder traversal of a binary tree */ void inorder(Node* temp)
inorder(temp->left); cout << temp->data << ' '; inorder(temp->right); } // Driver code int main() { Node* root = CreateNode(10); root->left = CreateNode(11); root->left->left = CreateNode(7); root->right = CreateNode(9); root->right->left = CreateNode(15); root->right->right = CreateNode(8); cout << "Inorder traversal before insertion: "; inorder(root); cout << endl; int key = 12; root = InsertNode(root, key); cout << "Inorder traversal after insertion: "; inorder(root); cout << endl; return 0; } Xulosa Men bu mustaqil ishida binary daraxtlarhaqida, binary daraxtlar ustida amallar bajarishni o’rgandim. Foydalanilgan adabiyotlar http//fayllar.org http//Wikipedia.org http//geeksforgeeks.org http//hozir.org Download 141.5 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling