Пример #1
0
def heap_peak(name):
    if name in heapdict.keys():
        v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        return str(name.peek())
    else:
        return "There is no heap with desired name", 400
Пример #2
0
def heap_peak(name):
    if name in heapdict.keys():
        v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        return str(name.peek())
    else:
        return "There is no heap with desired name", 400
Пример #3
0
 def Testremove(self):
     heap1 = BinHeap_Array()
     heap1.insert(9)
     heap1.insert(5)
     heap1.insert(4)
     heap1.insert(3)
     heap1.insert(2)
     self.assertEqual(heap1.remove(), 2)
     self.assertEqual(heap1.remove(), 3)
     self.assertEqual(heap1.remove(), 4)
Пример #4
0
def heap_get(name=None):
    if name == None:
        return "Please enter a name for the heap you want to inquiry!", 400
    if name in heapdict.keys():
	v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        return "The size of the heap is " + str(name.size) + '\n' + "The heap is (in array format):" + ','.join(map(str,name._print()))
    else:
        return "There is no heap with desired name", 400
Пример #5
0
def heap_pop(name):
    if name in heapdict.keys():
        tmp = name
        v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        out = str(name.remove())
        heapdict[tmp] = name._print()
        return out
    else:
        return "There is no heap with desired name", 400
Пример #6
0
def heap_get(name=None):
    if name == None:
        return "Please enter a name for the heap you want to inquiry!", 400
    if name in heapdict.keys():
        v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        return "The size of the heap is " + str(
            name.size) + '\n' + "The heap is (in array format):" + ','.join(
                map(str, name._print()))
    else:
        return "There is no heap with desired name", 400
Пример #7
0
 def Testremove(self):
     heap1 = BinHeap_Array()
     heap1.insert(9)
     heap1.insert(5)
     heap1.insert(4)
     heap1.insert(3)
     heap1.insert(2)
     self.assertEqual(heap1.remove(),2)
     self.assertEqual(heap1.remove(),3)
     self.assertEqual(heap1.remove(),4)
Пример #8
0
def heap_timearray():

    # Request LENGTH
    LENGTH = request.args.get('length', type=int)
    if LENGTH == None or LENGTH <= 0:
        return "Please enter a valid length!", 400

    # Request SEED
    SEED = request.args.get('seed', 100)  # Use a default seed of 100
    (insert_time, remove_time) = BinHeap_Array().rand(LENGTH, SEED)
    return "The length is " + str(LENGTH) + ", and the seed is " + str(SEED) + '\n' \
    "The insertion time is " + str(insert_time) + '\n' + "The popping time is " + str(remove_time) + '\n'
Пример #9
0
def heap_pop(name):
    if name in heapdict.keys():
        tmp = name
        v = heapdict[name]
        name = BinHeap_Array()
        name.heapify(v)
        out = str(name.remove())
        heapdict[tmp] = name._print()
        return out
    else:
        return "There is no heap with desired name", 400
Пример #10
0
 def Testheapify(self):
     heap1 = BinHeap_Array()
     heap1.heapify([9])
     self.assertEqual(heap1._print(),[9])
     heap1.heapify([5,4,3,2])
     self.assertEqual(heap1._print(),[2,3,4,9,5])
Пример #11
0
 def Testinsert(self):
     heap1 = BinHeap_Array()
     heap1.insert(9)
     self.assertEqual(heap1.peek(),9)
     heap1.insert(5)
     self.assertEqual(heap1.peek(),5)
     heap1.insert(4)
     self.assertEqual(heap1.peek(),4)
     heap1.insert(6)
     self.assertEqual(heap1.peek(),4)
Пример #12
0
 def Testheapify(self):
     heap1 = BinHeap_Array()
     heap1.heapify([9])
     self.assertEqual(heap1._print(), [9])
     heap1.heapify([5, 4, 3, 2])
     self.assertEqual(heap1._print(), [2, 3, 4, 9, 5])
Пример #13
0
 def Testinsert(self):
     heap1 = BinHeap_Array()
     heap1.insert(9)
     self.assertEqual(heap1.peek(), 9)
     heap1.insert(5)
     self.assertEqual(heap1.peek(), 5)
     heap1.insert(4)
     self.assertEqual(heap1.peek(), 4)
     heap1.insert(6)
     self.assertEqual(heap1.peek(), 4)