انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

12: Search and Traversing Operations in BST

الكلية كلية تكنولوجيا المعلومات     القسم قسم البرامجيات     المرحلة 2
أستاذ المادة صفا سعد عباس المرعب       14/06/2018 19:28:26
Search and Traversing Operations in BST
Finding (Searching) a Node in a Binary Search Tree
Finding a node with a specific key is the simplest of the major tree operations.
Figure 5: Finding node 57.
// find or search a node with a given key
Public void Search (int key) // Iterative manner or
{
if (root = = null)
return ;
else
{
node current = root;
While (current . Data ! = key)
{
If (key < current . Data) // go left
current = current . leftChild ;
else
// or go right
current = current . rightChild ;
if (current = = null) // if no child
{
S.O.P ("not found") ;
Return ;
}
}
S.O.P ("found") ;
}
}
///////////////////////////////////////////////////////////////////
College of Information Technology / Software Department
………………………………………………………..
Data Structures / Second Class / 2017-2018
LEC. 10
if (root = = null)
return ;
else
{
node current = root;
while (current ! = null)
{
if (key = = current . data)
{
S.O.P ("found") ;
return ;
}
else
if (key < current . data)
current = current . leftChild ;
else
current = current . rightChild ;
}
غير موجود //
S.O.P ("not found") ;
}
35
// Recursive manner
? Firstly point to root by current
Public void Search (node current , int key)
{
if (current = = null)
{
S.O.P ("not found") ;
Return ;
}
If (key = = current . Data) // current key is what you search for
S.O.P ("found") ;
Else
If (key < current . Data)
Search (current . leftChild , key) ;
Else
Search (current . rightChild , key) ;
}
Binary Tree Traversals
There are three traversals manners (preorder, inorder, postorder) to print the tree s nodes.

المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .