-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPila.py
More file actions
54 lines (40 loc) · 1.35 KB
/
Copy pathPila.py
File metadata and controls
54 lines (40 loc) · 1.35 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
import os
from graphviz import Digraph, nohtml
class NodoPi():
def __init__(self, x, y):
self.x = x
self.y = y
self.sig = None
class Pila():
def __init__(self):
self.cabeza = None
def push(self,x,y):
nuevo = NodoPi(x, y)
if self.cabeza is None:
self.cabeza = nuevo
else:
nuevo.sig = self.cabeza
self.cabeza = nuevo
def impri(self):
temp = self.cabeza
if temp is None:
print("La pila esta vacia")
else:
while temp is not None:
temp = temp.sig
print(temp.x, ",", temp.y)
def peek(self):
if self.cabeza is None:
print("Esta vacia")
else:
print("quitar: " + str(self.cabeza.x + "," + self.cabeza.y))
def graf2(self):
g = Digraph('Pila', filename='grafica2.dot', format='jpg' , node_attr={'shape': 'record', 'height': '.1'})
temp = self.cabeza
g.graph_attr['rankdir'] = 'LR'
while(temp != None):
g.node(str(temp), nohtml('<f0> |<f1> '+str(temp.x)+','+str(temp.y)+'|<f2>'))
g.edge(str(temp),str(temp.sig))
temp = temp.sig
g.save()
os.system("dot grafica2.dot -o imagen2.jpg -Tjpg -Gcharset=utf8")