Advertisement
myselffran

Untitled

Jun 28th, 2022
1,028
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Jun 28 14:25:43 2022
  4.  
  5. @author: franc
  6. """
  7.  
  8.  
  9. class Node():
  10.    
  11.     def __init__(self, value):
  12.         self.value = value
  13.         self.left  = None
  14.         self.right  = None
  15.        
  16.        
  17.     def set_left(self, left_value):
  18.         self.left = Node(left_value)
  19.         return self
  20.        
  21.     def set_right(self, right_value):
  22.         self.right = Node(right_value)
  23.         return self
  24.        
  25.        
  26. class Arbol:
  27.    
  28.     def __init__(self, root):
  29.         self.root = Node(root)
  30.        
  31.     def __value_chek(pointer, search_value):
  32.         for side in [pointer.left, pointer.right]:
  33.             if search_value == side.value:
  34.                 print('Encontrado')
  35.        
  36.        
  37.        
  38.     def search(self, search_value):
  39.        
  40.         if search_value == self.root.value:
  41.             print('Encontrado')
  42.             return
  43.         else:
  44.             pointer = self.root
  45.            
  46.            
  47.            
  48.            
  49.        
  50.        
  51.        
  52.        
  53.        
  54. a = Arbol(0)
  55.  
  56. a.root.set_left(1)
  57. a.root.set_right(2)
  58.  
  59. a.root.left.set_left(3)
  60. a.root.left.set_right(4)
  61.  
  62. print(a.root.value)
  63. print(a.root.left.value)
  64. print(a.root.left.left.value)
  65. print(a.root.left.right.value)
  66.  
  67. print(a.root.right.value)
  68.  
  69. a.search(3)
Advertisement
RAW Paste Data Copied
Advertisement