# -*- coding: utf-8 -*-

class Stack:
    '''
        class for stack, use a Python list
        attributes :
        - size : int 
        - items : list
        methods :
        - push(x) : push the data x which is an instance of Item 
        - pop() : if the stack is not empty, pop and return the data, else do nothing and return None
        - print() : print the attributes
    '''
    def __init__(self):  # fonction d'initialisation d'une nouvelle instance (objet) de la classe
        self.size = 0
        self.items = list()
    
    def push(self,x):
        self.size += 1
        self.items.append(x)

    def pop(self):
        if self.size>0:
            self.size -= 1
            return self.items.pop()
        return None
        
    def print(self):  # fonction d'affichage de la pile
        print('size=',self.size,', items=',self.items)


class Node: 
    '''
        Class for nodes of a binary tree
        Attributes :
        - left : None or Node
        - right : None or Node
        - data : Item
    '''
    def __init__(self,key):
        self.left = None
        self.right = None
        self.data = key


class Tree:
    '''
        Class for binary tree
        Attributes :
        - size : int
        - root : None or Node
        Methods :
        - infix_print() : print the tree according infix order
    '''
    def __init__(self):
        self.root = None
        self.size = 0
 
    def infix_print_rec(self,root):
        if root is not None:
            self.infix_print_rec(root.left)
            print(root.data, end=', ')
            self.infix_print_rec(root.right)

    def infix_print(self):
        print("Tree : ", end='')
        self.infix_print_rec(self.root)
        print()

                
class BST(Tree):
    '''
        Class for ABR
        Derivate from Tree
    '''
    pass # mot clé Python dire qu'on ne fait rien quand on est obligé d'écrire une instruction


################################  Tests  ################################## 

s=Stack()
s.print()
s.push(1)
s.print()
s.push(2)
s.print()
s.pop()
s.print()
s.pop()
s.print() 

       

t = BST()
t.root = Node(4)
t.root.right = Node(5)
t.infix_print()
