コード例 #1
0
def convert_base(decimal, base):
    digits = "0123456789ABCDEF"
    stack = StackAA()
    number = decimal
    while number > 0:
        rem = number % base
        stack.push(rem)
        number = number // base

    items = []
    while not stack.is_empty():
        items.append(digits[stack.pop()])
    return "".join(items)
コード例 #2
0
def convert_base(decimal, base):
    digits = "0123456789ABCDEF"
    stack = StackAA()
    number = decimal
    while number > 0:
        rem = number % base
        stack.push(rem)
        number = number // base

    items = []
    while not stack.is_empty():
        items.append(digits[stack.pop()])
    return "".join(items)
コード例 #3
0
    def testALStack(self):
        stack_aa = StackAA()
        self.assertIsNone(stack_aa.peek())
        self.assertEqual(stack_aa.size(), 0)
        self.assertTrue(stack_aa.is_empty())

        stack_aa.push("Marcus")
        stack_aa.push(5)
        stack_aa.push(False)
        stack_aa.push(67.128)
        stack_aa.push("Carlos")
        stack_aa.push(StackLLNode)
        stack_aa.push(8)

        self.assertFalse(stack_aa.is_empty())
        self.assertEqual(stack_aa.peek(), 8)
        self.assertEqual(stack_aa.size(), 7)

        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()

        self.assertFalse(stack_aa.is_empty())
        self.assertEqual(stack_aa.peek(), 67.128)
        self.assertEqual(stack_aa.size(), 4)

        self.assertEqual(str(stack_aa), "['Marcus', 5, False, 67.128]")

        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()

        self.assertIsNone(stack_aa.peek())
        self.assertEqual(stack_aa.size(), 0)
        self.assertTrue(stack_aa.is_empty())
コード例 #4
0
    def testALStack(self):
        stack_aa = StackAA()
        self.assertIsNone(stack_aa.peek())
        self.assertEqual(stack_aa.size(),0)
        self.assertTrue(stack_aa.is_empty())

        stack_aa.push("Marcus")
        stack_aa.push(5)
        stack_aa.push(False)
        stack_aa.push(67.128)
        stack_aa.push("Carlos")
        stack_aa.push(StackLLNode)
        stack_aa.push(8)

        self.assertFalse(stack_aa.is_empty())
        self.assertEqual(stack_aa.peek(), 8)
        self.assertEqual(stack_aa.size(), 7)

        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()

        self.assertFalse(stack_aa.is_empty())
        self.assertEqual(stack_aa.peek(), 67.128)
        self.assertEqual(stack_aa.size(), 4)

        self.assertEqual(str(stack_aa), "['Marcus', 5, False, 67.128]")

        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()
        stack_aa.pop()

        self.assertIsNone(stack_aa.peek())
        self.assertEqual(stack_aa.size(),0)
        self.assertTrue(stack_aa.is_empty())