Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. lista = [None]
  2. lDown = 0
  3. lUp = 0
  4.  
  5. def linearProbing(x):
  6.     global lDown
  7.     global lUp
  8.    
  9.     if fullList():
  10.         return "The list is full"
  11.     l = x % len(lista)
  12.     if lista[l] != None and lDown <= lUp:
  13.         linearProbing1(x)
  14.         lDown += 1
  15.     else:
  16.         linearProbing2(x)
  17.         lUp += 1
  18.        
  19.     print lDown
  20.     print lUp
  21.        
  22. def createList(size):
  23.     global lista
  24.     lista = [None] * size
  25.  
  26. def linearProbing1(x):
  27.     l = x % len(lista)
  28.     state = 0
  29.     while state != 1:
  30.         if lista[l] == None:
  31.             lista[l] = x
  32.             state = 1
  33.         elif l == len(lista)-1:
  34.             l = 0
  35.         else:
  36.             l += 1
  37.     print lista        
  38.  
  39. def linearProbing2(x):
  40.     l = x % len(lista)
  41.     state = 0
  42.     while state != 1:
  43.         if lista[l] == None:
  44.             lista[l] = x
  45.             state = 1
  46.         elif l == 0:
  47.             l = len(lista)-1
  48.         else:
  49.             l -= 1
  50.     print lista
  51.  
  52. def fullList():
  53.     for i in range(0, len(lista)):
  54.         if lista[i] == None:
  55.             return False
  56.     return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement