Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
erks committed Dec 2, 2012
2 parents b739424 + ce80c83 commit b5d9a7c
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ class DS:
MIN_HEAP = 3
MAX_HEAP = 4
HASHTABLE = 5
NUM_STRUCTURES = 5
NUM_STRUCTURES = 7

Binary file removed DS.pyc
Binary file not shown.
Binary file removed arr.pyc
Binary file not shown.
Binary file removed bst.pyc
Binary file not shown.
Binary file removed btree.pyc
Binary file not shown.
35 changes: 34 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ class SD:
data structure.
"""
def __init__(self, isTesting, which = None):

print(which)
if which == DS.ARRAY:
print "Array"
self.struct = Arr()
elif which == DS.SORTED_ARRAY:
print "S Array"
self.struct = SArr()
elif which == DS.MAX_HEAP:
print "M Heap"
self.struct = MaxHeap()
elif which == DS.MIN_HEAP:
print "min heap"
self.struct = MinHeap()
elif which == DS.BINARY_SEARCH_TREE:
print "bst"
self.struct = Balanced_BST()
else:
print "Default to Array"
Expand All @@ -39,39 +44,67 @@ def __init__(self, isTesting, which = None):
self.get_min_ctr = 0
self.extract_ctr = 0
self.extract_min_ctr = 0
self.num_ops = 0

self.isTesting = isTesting
self.len = 0

def contains(self, key):
self.contains_ctr += 1
self.num_ops += 1
return self.struct.contains(key)

def add(self, key):
self.struct.add(key)
self.len += 1
self.add_ctr += 1
self.num_ops += 1

def remove(self, key):
self.struct.remove(key)
self.len -= 1
self.num_ops += 1
self.remove_ctr += 1

def get(self, index):
self.get_ctr += 1
self.num_ops += 1
return self.struct.get(index)

def get_min(self):
self.get_min_ctr += 1
self.num_ops += 1
return self.get(self, 0)

def get_max(self):
self.get_max_ctr += 1
self.num_ops += 1
return self.get(self, len - 1)

def extract(self, index):
toReturn = get(self, index)
remove(self, index)
self.extract_ctr += 1
self.num_ops += 1
return toReturn

def extract_min(self):
extract(self, 0)
self.extract_min_ctr += 1
self.num_ops += 1

def extract_max(self):
extract(self, self.len - 1)
self.extract_max_ctr += 1
self.num_ops += 1

def size(self):
return self.len

def reeval(self):
if self.isTesting:
return
else:
print "NEED TO IMPLEMENT"


Binary file removed main.pyc
Binary file not shown.
Binary file removed maxheap.pyc
Binary file not shown.
Binary file removed minheap.pyc
Binary file not shown.
Binary file removed sarr.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test():

print(str(s_data.get(0)) + " should be 0")

s_data = SD(True)
s_data = SD()

# --------------
# Array Test
Expand Down
25 changes: 25 additions & 0 deletions test_compile_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test File

from main import *
import itertools
from random import *
from sarr import *
from minheap import *
from maxheap import *
from bst import *

def test():
s_data.len = 0

for x in choice([x for x in itertools.permutations(range(10))]):
s_data.add(x)

print(str(s_data.contains(3)) + " should be true")

s_data.remove(3)
print(str(s_data.contains(3)) + " should be false")

print(str(s_data.get(0)) + " should be 0")

s_data = SD(6, True)
test()

0 comments on commit b5d9a7c

Please sign in to comment.