mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'''
|
||||
A AVL tree
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Node:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import print_function
|
||||
|
||||
def printDist(dist, V):
|
||||
print("\nVertex Distance")
|
||||
for i in range(V):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Author: OMKAR PATHAK
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph():
|
||||
def __init__(self):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Author: OMKAR PATHAK
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph():
|
||||
def __init__(self):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
|
||||
def printDist(dist, V):
|
||||
print("\nVertex Distance")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph:
|
||||
def __init__(self, vertex):
|
||||
self.vertex = vertex
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
class Graph:
|
||||
|
||||
def __init__(self, vertex):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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=" ")
|
||||
|
||||
Reference in New Issue
Block a user