Merge pull request #234 from ashu01/develope-1

Refactor
This commit is contained in:
Harshil 2018-01-01 10:25:54 +05:30 committed by GitHub
commit ee6e5a42cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 23 deletions

View File

@ -13,8 +13,8 @@ def chunker(seq, size):
def prepare_input(dirty):
"""
Prepare the plaintext by uppcasing it
and seperating repeated letters with X's
Prepare the plaintext by up-casing it
and separating repeated letters with X's
"""
dirty = ''.join([c.upper() for c in dirty if c in string.ascii_letters])
@ -38,7 +38,7 @@ def prepare_input(dirty):
def generate_table(key):
# I and J are used interchangably to allow
# I and J are used interchangeably to allow
# us to use a 5x5 table (25 letters)
alphabet = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
# we're using a list instead of a '2d' array because it makes the math

View File

@ -1,6 +1,6 @@
'''
A AVL tree
'''
"""
An AVL tree
"""
from __future__ import print_function
@ -101,10 +101,10 @@ class AVL:
if height_left > height_right:
left_child = n.left
if left_child is not None:
h_right = (right_child.right.height
if (right_child.right is not None) else 0)
h_left = (right_child.left.height
if (right_child.left is not None) else 0)
h_right = (left_child.right.height
if (left_child.right is not None) else 0)
h_left = (left_child.left.height
if (left_child.left is not None) else 0)
if (h_left > h_right):
self.rotate_left(n)
break

View File

@ -1 +1 @@
Arrays implimentation using python programming.
Arrays implementation using python programming.

View File

@ -7,11 +7,11 @@ def printDist(dist, V):
print(i,"\t",int(dist[i]),end = "\t")
else:
print(i,"\t","INF",end="\t")
print();
print()
def BellmanFord(graph, V, E, src):
mdist=[float('inf') for i in range(V)]
mdist[src] = 0.0;
mdist[src] = 0.0
for i in range(V-1):
for j in range(V):
@ -35,13 +35,13 @@ def BellmanFord(graph, V, E, src):
#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 = [dict() for j in range(E)]
for i in range(V):
graph[i][i] = 0.0;
graph[i][i] = 0.0
for i in range(E):
print("\nEdge ",i+1)

View File

@ -7,7 +7,7 @@ def printDist(dist, V):
print(i,"\t",int(dist[i]),end = "\t")
else:
print(i,"\t","INF",end="\t")
print();
print()
def minDist(mdist, vset, V):
minVal = float('inf')
@ -25,7 +25,7 @@ def Dijkstra(graph, V, src):
for i in range(V-1):
u = minDist(mdist, vset, V)
vset[u] = True;
vset[u] = True
for v in range(V):
if (not vset[v]) and graph[u][v]!=float('inf') and mdist[u] + graph[u][v] < mdist[v]:
@ -38,20 +38,20 @@ def Dijkstra(graph, V, src):
#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
gsrc = int(input("\nEnter shortest path source:"))
Dijkstra(graph, V, gsrc)

View File

@ -8,7 +8,7 @@ class Graph:
self.dp = [[math.inf for j in range(0,N)] for i in range(0,N)] # dp[i][j] stores minimum distance from i to j
def addEdge(self, u, v, w):
self.dp[u][v] = w;
self.dp[u][v] = w
def floyd_warshall(self):
for k in range(0,self.N):