Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # a) Sa se defineasca o lista de vehicule autosortabila
- # b) Sa se numere cate vehicule se afla in lista
- # c) Sa se defineasca o functie care filtreaza si obtine o lista de automturisme pornind
- # # de la lista initiala
- # d) analog -> o lista de camioane
- # 1. Vehicul - nrInmatriculare / anInmatriculare
- # 2(1) Autoturism - motor / nrLocuri
- # 3(1) Camion - tonaj / nrRemorci
- class Vehicul():
- def __init__(self, nrInmatriculare, anInmatriculare):
- self.nrInmatriculare = nrInmatriculare
- self.anInmatriculare = anInmatriculare
- self.link = None
- def setareLink(self, element):
- self.link = element
- def getLink(self):
- return self.link
- def __gt__(self, element):
- if element != None:
- if element.anInmatriculare < self.anInmatriculare:
- return True
- else:
- return False
- def __repr__(self):
- return "Vehiculul " + str(self.nrInmatriculare) + " " + str(self.anInmatriculare)
- class Autoturism(Vehicul):
- def __init__(self, nrInmatriculare, anInmatriculare, motor, nrLocuri):
- super().__init__(nrInmatriculare, anInmatriculare)
- self.motor = motor
- self.nrLocuri = nrLocuri
- def __repr__(self):
- return "Autoturismul " + str(self.nrInmatriculare) + " " + str(self.anInmatriculare) + \
- " " + str(self.motor) + " " + str(self.nrLocuri)
- class Camion(Vehicul):
- def __init__(self, nrImatriculare, anInmatriculare, tonaj, nrRemorci):
- super().__init__(nrImatriculare, anInmatriculare)
- self.tonaj = tonaj
- self.nrRemorci = nrRemorci
- def __repr__(self):
- return "Camionul " + str(self.nrInmatriculare) + " " + str(self.anInmatriculare) + \
- " " + str(self.tonaj) + " " + str(self.nrRemorci)
- class Lista():
- def __init__(self):
- self.root = None
- def adauga(self, element):
- if element != None: #daca elementul nu este gol
- # in cazul in care adaugi primul element
- if self.root == None:
- self.root = element
- self.link = None
- # in cazul in care adaugi in mijlocul listei
- elif (element > self.root):
- succesor = None
- predecesor = None
- x = self.root # variabila locala
- while element > x.getLink() and x.getLink() != None:
- x = x.link
- if x.link == None: #adaugare element la capat
- x.link = element
- else: #adaugare in pozitie intermediara
- succesor = x.link
- predecesor = x
- element.link = succesor
- predecesor.link = element
- else:
- element.link = self.root
- self.root = element
- # in cazul in care adaugi la capatul listei
- # nr 1 2 3 4 5
- # root None None 1 2 3 4
- # link 1 2 3 4 5 6
- def __repr__(self):
- s = " "
- i = self.root
- while i!=None:
- s = s + str(i) + " "
- print(i)
- i = i.link
- return s
- autoturism1 = Autoturism("CJ01TRE", 2004, 100, 4)
- print(autoturism1)
- camion1 = Camion("B01BMW", 2002, 80, 2)
- print(camion1)
- print("Este mai mare: ")
- if camion1 > autoturism1:
- print(camion1)
- print("-----------------")
- lista1 = Lista()
- lista1.adauga(autoturism1)
- lista1.adauga(camion1)
- print(lista1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement