Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. class Nod:
  2. def __init__(self, e):
  3. self.e = e
  4. self.urm = None
  5.  
  6.  
  7. class Lista:
  8. def __init__(self):
  9. self.prim = None
  10.  
  11.  
  12. '''
  13. crearea unei liste din valori citite pana la 0
  14. '''
  15.  
  16.  
  17. def creareLista():
  18. lista = Lista()
  19. lista.prim = creareLista_rec()
  20. return lista
  21.  
  22.  
  23. def creareLista_rec():
  24. x = int(input("x="))
  25. if x == 0:
  26. return None
  27. else:
  28. nod = Nod(x)
  29. nod.urm = creareLista_rec()
  30. return nod
  31.  
  32.  
  33. '''
  34. tiparirea elementelor unei liste
  35. '''
  36.  
  37. '''
  38. def tipar(lista):
  39. tipar_rec(lista.prim)
  40.  
  41.  
  42. def tipar_rec(nod):
  43. if nod != None:
  44. print(nod.e)
  45. tipar_rec(nod.urm)
  46. '''
  47.  
  48. '''
  49. program pentru test
  50. '''
  51.  
  52.  
  53.  
  54. def number(list):
  55. if list == []:
  56. return 0
  57. elif list[0] % 2 == 0:
  58. return list[0] + number(list[1:])
  59. elif list[0] % 2 != 0:
  60. return -list[0] + number(list[1:])
  61.  
  62. newList = []
  63.  
  64.  
  65. def difference(list1, list2):
  66.  
  67. if list1 == [] and newList == []:
  68. return list2
  69. elif list2 == [] and newList == []:
  70. return list1
  71. elif list1 == [] :
  72. #return list2
  73. return newList
  74. elif list2 == []:
  75. #return list1
  76. return newList
  77. elif list1[0] == list2[0]:
  78. return difference(list1[1:], list2[1:])
  79. elif list1[0] > list2[0]:
  80. newList.insert(0, list2[0])
  81. return difference(list1, list2[1:])
  82. elif list1[0] < list2[0]:
  83. newList.insert(0, list1[0])
  84. return difference(list1[1:], list2)
  85.  
  86.  
  87. def main():
  88. #list = creareLista()
  89. listtttttt = []
  90. list = [1, 2, 3, 4, 5, 6]
  91.  
  92. print(number(list))
  93.  
  94. list1 = [1, 2, 3, 4, 5, 6]
  95. list2 = [1, 3, 6]
  96. #list2 = []
  97. print(difference(list1, list2))
  98.  
  99. #tipar(list)
  100.  
  101.  
  102. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement