Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import csv
  2.  
  3.  
  4. class Node:
  5. def __init__(self, init_data):
  6. self.data = init_data
  7. self.next = None
  8. def get_data(self):
  9. return self.data
  10. def get_next(self):
  11. return self.next
  12. def set_data(self, new_data):
  13. self.data = new_data
  14. def set_next(self, new_next):
  15. self.next = new_next
  16.  
  17.  
  18.  
  19. class LinkedList:
  20. def __init__(self):
  21. self.head = None
  22. def is_empty(self):
  23. return self.head == None
  24. def add(self, item):
  25. temp = Node(item)
  26. temp.set_next(self.head)
  27. self.head = temp
  28.  
  29.  
  30. def print_list(self):
  31. currentNode = self.head
  32. if currentNode == None:
  33. return 0
  34. print(currentNode.get_data())
  35. while currentNode != None:
  36. currentNode = currentNode.get_next()
  37. if currentNode != None:
  38. print(currentNode.get_data())
  39.  
  40. def remove(self, item):
  41. current = self.head
  42. previous = None
  43. found = False
  44. while not found:
  45. if current.get_data() == item:
  46. found = True
  47. else:
  48. previous = current
  49. current = current.get_next()
  50. if previous == None:
  51. self.head = current.get_next()
  52. else:
  53. previous.set_next(current.get_next())
  54.  
  55. def search(self,item):
  56. current = self.head
  57. found = False
  58. while current != None and not found:
  59. if current.getData() == item:
  60. found = True
  61. else:
  62. current = current.getNext()
  63.  
  64. return found
  65.  
  66.  
  67.  
  68. def csv():
  69.  
  70. csv_file = open('dados.csv')
  71.  
  72.  
  73. for linha in csv_file:
  74. linha = linha.split(';')
  75. #print(linha)
  76. #print(len(linha))
  77.  
  78. csv_file.close()
  79. return (len(linha))
  80.  
  81.  
  82. def lista_ligada_cc():
  83. myList_cc = LinkedList()
  84. nmr = csv()
  85. #print(nmr)
  86. csv_file = open('dados.csv')
  87. i=0
  88. for linha in csv_file:
  89. linha = linha.split(';')
  90. if i==0:
  91. pass
  92. else:
  93. add = linha[1]
  94. myList_cc.add(add)
  95. i+=1
  96.  
  97. csv_file.close()
  98. myList_cc.print_list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement