Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- class Node:
- def __init__(self, init_data):
- self.data = init_data
- self.next = None
- def get_data(self):
- return self.data
- def get_next(self):
- return self.next
- def set_data(self, new_data):
- self.data = new_data
- def set_next(self, new_next):
- self.next = new_next
- class LinkedList:
- def __init__(self):
- self.head = None
- def is_empty(self):
- return self.head == None
- def add(self, item):
- temp = Node(item)
- temp.set_next(self.head)
- self.head = temp
- def print_list(self):
- currentNode = self.head
- if currentNode == None:
- return 0
- print(currentNode.get_data())
- while currentNode != None:
- currentNode = currentNode.get_next()
- if currentNode != None:
- print(currentNode.get_data())
- def remove(self, item):
- current = self.head
- previous = None
- found = False
- while not found:
- if current.get_data() == item:
- found = True
- else:
- previous = current
- current = current.get_next()
- if previous == None:
- self.head = current.get_next()
- else:
- previous.set_next(current.get_next())
- def search(self,item):
- current = self.head
- found = False
- while current != None and not found:
- if current.getData() == item:
- found = True
- else:
- current = current.getNext()
- return found
- def csv():
- csv_file = open('dados.csv')
- for linha in csv_file:
- linha = linha.split(';')
- #print(linha)
- #print(len(linha))
- csv_file.close()
- return (len(linha))
- def lista_ligada_cc():
- myList_cc = LinkedList()
- nmr = csv()
- #print(nmr)
- csv_file = open('dados.csv')
- i=0
- for linha in csv_file:
- linha = linha.split(';')
- if i==0:
- pass
- else:
- add = linha[1]
- myList_cc.add(add)
- i+=1
- csv_file.close()
- myList_cc.print_list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement