-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularDoble.py
More file actions
69 lines (57 loc) · 1.87 KB
/
Copy pathCircularDoble.py
File metadata and controls
69 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os, csv
from graphviz import Digraph, nohtml
class NodoDoble():
def __init__(self, valor):
self.sig = None
self.ant = None
self.valor = valor
class CircularDoble():
def __init__(self):
self.inicio = None
self.fin = None
self.size = 0
def estaVacia(self):
return self.inicio is None
def getLista(self):
return lista
def getInicio(self):
return self.inicio
def getFin(self):
return self.fin
def cargamasiva(self):
with open('usuarios.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
aux = row['Usuario']
names = aux.replace(";","")
self.insertar_inicio(str(names))
self.graf2()
def insertar_inicio(self, valor):
nuevo = NodoDoble(valor)
if self.estaVacia():
nuevo.ant = self.fin
nuevo.sig = self.inicio
self.inicio = nuevo
self.fin = nuevo
else:
self.inicio.ant = nuevo
nuevo.sig = self.inicio
self.inicio = nuevo
self.fin.sig = nuevo
self.inicio.ant = self.fin
self.size += 1
def graf2(self):
g = Digraph('CircularDoble', filename='grafica4.dot', format='jpg' , node_attr={'shape': 'record', 'height': '.1'})
temp = self.inicio
g.graph_attr['rankdir'] = 'LR'
while(temp != None):
g.node(str(temp), nohtml('<f0> |<f1> ' + str(temp.valor) + '|<f2>'), )
g.edge(str(temp), str(temp.sig))
g.edge(str(temp), str(temp.ant))
temp = temp.sig
if temp == self.fin.sig:
break
g.save()
os.system("dot grafica4.dot -o imagen4.jpg -Tjpg -Gcharset=utf8")
lista = CircularDoble()
lista.cargamasiva()