コード例 #1
0
def palchecker(string):
    chardeque = Deque()
    for i in string:
        chardeque.addRear(i)
    stillEqual =1
    while chardeque.size > 1 and stillEqual==1:
        first = chardeque.removeFront()
        last=chardeque.removeRear()
        if first!=last:
            stillEqual = 0
    return stillEqual
コード例 #2
0
def palchecker(astring):
    chardeque = Deque()
    for ch in astring:
        chardeque.addRear(ch)
    stillequal = True
    while chardeque.size() > 1 and stillequal:
        first = chardeque.removeFront()
        last = chardeque.removeRear()
        if first != last:
            stillequal = False
    return stillequal
def palChecker(aString):
    chardeque = Deque()
    stillEqual = True

    for ch in aString:
        chardeque.addFront(ch)

    while chardeque.size() > 1 and stillEqual:
        first = chardeque.removeFront()
        last = chardeque.removeRear()
        if first != last:
            stillEqual = False

    return stillEqual
コード例 #4
0
def palindrome_checker(s):
    deque = Deque()
    still_equal = True

    for ch in s:
        deque.add_rear(ch)

    while deque.size() > 1 and still_equal:
        front = deque.remove_front()
        rear = deque.remove_rear()
        if front != rear:
            still_equal = False

    return still_equal
コード例 #5
0
def palindrome_checker(string):
    """判断一个字符串是不是回文字符串

    :param string: str
    :return: bool
    """
    d = Deque()
    for s in string:
        d.addRear(s)
    while d.size() > 1:
        first = d.removeFront()
        last = d.removeRear()
        if first != last:
            return False
    return True
コード例 #6
0
def isPalindrome(str):
    deq = Deque()

    for ch in str:
        deq.addRear(ch)

    temp = True

    while deq.size() > 1 and temp:
        first = deq.removeFront()
        last = deq.removeRear()
        if first != last:
            temp = False

    return temp
コード例 #7
0
def palChecker(inputString):
    q = Deque()

    for c in inputString:
        q.addRear(c)

    equal = True

    while q.size() > 1 and equal:
        first = q.removeFront()
        last = q.removeRear()

        if first != last:
            equal = False

    return equal
コード例 #8
0
def pal_checker(a_string):
    char_deque = Deque()

    # Store the characters of the string into a Deque
    for ch in a_string:
        # Process the string from left to right and add each character to the rear of the deque
        char_deque.addRear(ch)

    still_Equal = True

    # Checks if deque is down to one character and is true
    while char_deque.size() > 1 and still_Equal:
        # Remove both front and rear, compare them, and continue only if they match. Keep matching first and last items, until we either run out of characters or be left with size = 1 depending on whether the length of string was even or odd.
        first = char_deque.removeFront()
        last = char_deque.removeRear()
        if first != last:
            still_Equal = False

    return still_Equal
コード例 #9
0
def palchecker(aString):
    '''
    把字符存进双端队列里,
    再分别从头尾出队元素,
    逐一配对,是否相等
    '''
    chardeque = Deque()

    for ch in aString:
        chardeque.addRear(ch)

    stillEqual = True

    while chardeque.size() > 1 and stillEqual:
        first = chardeque.removeFront()
        last = chardeque.removeRear()
        if first != last:
            stillEqual = False

    return stillEqual
コード例 #10
0
def palindrome_checker(text):
    reversed_text = Deque()

    for char in text:
        reversed_text.addRear(char)
コード例 #11
0
# 4.15 ----------------- WHAT IS A DEQUE?
'''
Deque:
- Also known as a double-ended queue, is an ordered collection of items similar to the queue. 
- It has two ends, a front an a rear, and the items remain positioned in the collection. 
- Main difference is the unrestrictive nature of adding and removing items.
  - New items can be added at either the front of the rear. 
  - Likewise, existing items can be removed from either end.


Strength of Deques:
- In a sense, it provides all the capabilites of stacks and queues in a single data structure.
'''

# 4.16 ----------------- THE DEQUE ABSTRACT DATA TYPE
'''
Deque() : Creates a new deque that is empty. It needs no parameters and returns an empty deque.

addFront(item) : Adds a new item to the front of the deque. It needs the item and returns nothing.

addRear(item) : Adds a new item to the rear of the deque. It needs the item and returns nothing.

removeFront() : Removes the front item from the deque. It needs no parameters and returns the item. The deque is modified.

removeRear() : Removes the rear item from the deque. It needs no parameters and returns the item. The deque is modified.

isEmpty() : Tests to see whether the deque is empty. It needs no parameters and returns a boolean value.

size() : Returns the number of items in the deque. It needs no parameters and returns an integer.
'''