,   CyberForum.ru

- C++

 
Artishok
   Artishok
277 / 276 / 32
: 27.12.2009
: 1,767
13.12.2010, 13:33     #1
,, ( x ) .
,, ! .
. ?
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int rightmost(uzel *root)//ñ*ìûé ïð*âûé
{
  while (root->right != NULL)//ïîê* *å äîéäåò äî ïð*âîãî ñ ññûëêîé 0
    root = root->right;//ïî ïð*âûì ïîäóçë*ì ø*ã*òü
  return root->key;//âåð*ÿåì òî ÷òî òóä* ç*òåñ*ëîñü
}
 
uzel* del_tree(uzel *root, int val)//óä*ëå*èå
{
  if (root==0) return 0;//åñëè 0 ò*ê 0
  if (root->key == val) //åñëè **øëè òî
  {
        //ýòî ýëåìå*ò-ëèñò
     if (root->left==0 && root->right==0) 
     {
      delete root;//äîñò*òî÷*î ïðîñòî óä*ëèòü
      return 0;
     }
     if (root->right==0 && root->left != 0)//åñëè åñòü îäè* ïîòîìîê ëåâûé 
     {
      uzel *temp = root->left;//òî ïåðåìå**îé òèï* "óçåë" ç*ïèøåì ç**÷å*èå óçë*-ïîòîìê* ñëåâ*
      delete root;
      return temp;
     }
     if (root->left==0 && root->right != 0) //òî æå äëÿ ïð*âîãî
     {
      uzel *temp = root->right;
      delete root;
      return temp;
     }
     root->key = rightmost(root->left);//òåïåðü â óä*ëÿåìîé ïîçèöèè áóäåò ñòîÿòü ýëåìå*ò ñ*ìûé ïð*âûé ëåâîãî ïîääåðåâ*
     root->left = del_tree(root->left, root->key);//èùåì â ëåâîì ïîääåðåâå ýëåìå*ò ñ óä*ëÿåìûì ç**÷å*èåì è ïðîâîäèì åãî äåçè*òåãð*öèþ
     return root;
  }
  if (val < root->key)//åñëè ç**÷å*èå ìå*üøå òîãî ÷òî â êîð*å òî âûïîë*èòü âñå *åîáõîäèìûå îïåð*öèÿ äëÿ ëåâîãî ïîääåðåâ* 
  {
   root->left = del_tree(root->left, val);
   return root;
  }
  if (val > root->key)//òî æå äëÿ ïð*âîãî 
  { 
   root->right = del_tree(root->right, val);
   return root;
  }
 return root;
}
.
?

11 16
.
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
13.12.2010, 13:33    
:

C++ , ,
C++ ()
. C++
C++ RB tree
C++ ( )
C++
C++
C++ ?



:
.
east1
5 / 5 / 1
: 08.05.2010
: 30
18.12.2010, 17:00     #2
.
Yandex
18.12.2010, 17:00    

: 21:49. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru