Modernize Python 2 code to get ready for Python 3

This commit is contained in:
cclauss
2017-11-25 12:41:55 +01:00
parent 4e06949072
commit e31c780d94
17 changed files with 38 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
'''
A AVL tree
'''
from __future__ import print_function
class Node:

View File

@@ -1,3 +1,5 @@
from __future__ import print_function
def printDist(dist, V):
print("\nVertex Distance")
for i in range(V):

View File

@@ -1,4 +1,6 @@
# Author: OMKAR PATHAK
from __future__ import print_function
class Graph():
def __init__(self):

View File

@@ -1,4 +1,6 @@
# Author: OMKAR PATHAK
from __future__ import print_function
class Graph():
def __init__(self):

View File

@@ -1,3 +1,4 @@
from __future__ import print_function
def printDist(dist, V):
print("\nVertex Distance")

View File

@@ -1,3 +1,4 @@
from __future__ import print_function
def printDist(dist, V):
print("\nThe shortest path matrix using Floyd Warshall algorithm\n")
@@ -7,7 +8,7 @@ def printDist(dist, V):
print(int(dist[i][j]),end = "\t")
else:
print("INF",end="\t")
print();
print()
@@ -29,19 +30,19 @@ def FloydWarshall(graph, V):
#MAIN
V = int(input("Enter number of vertices: "));
E = int(input("Enter number of edges: "));
V = int(input("Enter number of vertices: "))
E = int(input("Enter number of edges: "))
graph = [[float('inf') for i in range(V)] for j in range(V)]
for i in range(V):
graph[i][i] = 0.0;
graph[i][i] = 0.0
for i in range(E):
print("\nEdge ",i+1)
src = int(input("Enter source:"))
dst = int(input("Enter destination:"))
weight = float(input("Enter weight:"))
graph[src][dst] = weight;
graph[src][dst] = weight
FloydWarshall(graph, V)

View File

@@ -1,3 +1,6 @@
from __future__ import print_function
class Graph:
def __init__(self, vertex):
self.vertex = vertex

View File

@@ -1,3 +1,6 @@
from __future__ import print_function
class Graph:
def __init__(self, vertex):

View File

@@ -2,6 +2,7 @@
# Author: Shubham Malik
# References: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
from __future__ import print_function
import math
import sys
# For storing the vertex set to retreive node with the lowest distance

View File

@@ -3,6 +3,9 @@
- This is an example of a double ended, doubly linked list.
- Each link references the next link and the previous one.
'''
from __future__ import print_function
class LinkedList:
def __init__(self):
self.head = None
@@ -70,4 +73,4 @@ class Link:
def __init__(self, x):
self.value = x
def displayLink(self):
print("{}".format(self.value), end=" ")
print("{}".format(self.value), end=" ")