Exemple #1
0
    def getSubArray(self, arr, num):
        result = []
        qmax, qmin = deque(), deque()
        i, j = 0, 0
        while i < len(arr):
            while j < len(arr):

                j += 1
Exemple #2
0
 def getMaxOfWindow(self, arr, w):
     result = [0 for i in range(len(arr)-w+1)]
     i, qmax = 0, deque()
     while i < len(arr):
         while qmax.size() > 0 and arr[qmax.back()] < arr[i]:  # Keep the deque in order
             qmax.pop_back()
         qmax.push_back(i)
         if qmax.front() == i-w:
             qmax.pop_front()
         if i>=w-1:
             result[i-w+1] = arr[qmax.front()]
         i += 1
     return result
def palindromeChecker(words):
    wordque1 = deque()
    equal = True

    for i in words:
        wordque1.addRear(i)

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

    return equal
Exemple #4
0
def palindromeQueue(string):
    mydeck = deque()

    for ch in string:
        mydeck.add_front(ch)
    success = False
    while mydeck.size() > 1:
        if mydeck.remove_front() == mydeck.remove_rear():
            success = True
            continue
        else:
            success = False
            break

    return success
Exemple #5
0
def palChecker(aString):
    d = deque()

    for i in aString:
        d.addRear(i)

    stillEqual = True

    while not d.isEmpty() and stillEqual:
        first = d.removeFront()
        last = d.removeRear()
        if first != last:
            stillEqual = False

    return stillEqual
 def __init__(self):
     self._deque = deque()
     self._lock = allocate_lock()
     self._rtc = RTC()
Exemple #7
0
from deque import deque

inp = input("Word:")

d = deque()

for i in inp:
    d.add_rear(i)

print(d.items)


def checkPalindrome(d):
    if d.size() == 1:
        return True
    while d.size() >= 2:
        if d.remove_front() != d.remove_rear():
            return False
    return True


print(inp, checkPalindrome(d))
Exemple #8
0
 def test_deque(self):
     self.assertEqual(
         deque.deque([
             'append 1', 'append 2', 'append 3', 'appendleft 4', 'pop',
             'popleft'
         ]), '1 2')
Exemple #9
0
    def start(self):
        filename1 = PhotoImage(file="1.png")
        filename2 = PhotoImage(file="2.PNG")
        self.rect.create_image(200, 400, image=filename1)
        self.rect.create_image(980, 400, image=filename2)
        self.rect.pack(expand=YES, fill=BOTH)
        #		self.rect.destroy()
        value = randint(10, 30)
        self.turn = 0
        self.countp = 0
        self.countd = 0
        self.val = value
        #		self.rect.grid()

        #		for i in range(0,200):
        #			Label(self.frame, text="").grid(row=i,column=i)
        for i in range(0, 200):
            Label(self.rect, text="", bg='blue').grid(row=i, column=i)

        Label(self.rect, text=value, font=(None, 15),
              bg='white').grid(row=8, column=60)
        self.rect.grid()
        self.rect.create_rectangle(178, 442, 212, 586, fill='white')
        self.rect.create_rectangle(966, 442, 1002, 586, fill='white')
        self.rect.create_rectangle(360, 280, 800, 320, fill='white')
        self.rect.grid()
        self.rect.grid()

        self.e1 = Entry(self.rect)
        self.e1.grid(row=31, column=28)
        Button(self.rect,
               text='Pick',
               bg='orange',
               width=16,
               command=self.pick1).grid(row=30, column=28)
        Button(self.rect,
               text='Drop',
               bg='green',
               width=16,
               command=self.drop1).grid(row=32, column=28)
        Label(self.rect, text=self.n1, font=(None, 15), bg='blue',
              fg='yellow').grid(row=34, column=28)

        self.e2 = Entry(self.rect)
        self.e2.grid(row=31, column=95)
        Button(self.rect,
               text='Pick',
               bg='orange',
               width=16,
               command=self.pick2).grid(row=30, column=95)
        Button(self.rect,
               text='Drop',
               bg='green',
               width=16,
               command=self.drop2).grid(row=32, column=95)
        Label(self.rect, text=self.n2, font=(None, 15), bg='blue',
              fg='yellow').grid(row=34, column=95)

        self.p = value
        self.d = deque()
        s = [8, 4, 2, 1, 0]
        self.p1 = MyStack()
        self.p2 = MyStack()
        self.q = MyQueue()
        for j in range(0, 5):
            for i in s:
                self.d.insert_at_last(i)
        self.d.slices()
        self.d.shuffle()
        self.sum1 = 0
        self.sum2 = 0

        for i in range(0, 5):
            self.d.slices()
            b1 = self.d.remove_at_front()
            self.p1.push(b1)
            self.sum1 += b1
            b2 = self.d.remove_at_last()
            self.p2.push(b2)
            self.sum2 += b2

        Label(self.rect,
              text=self.sum1,
              font=(None, 12),
              bg='blue',
              fg='white').grid(row=35, column=28, pady=5)
        Label(self.rect,
              text=self.sum2,
              font=(None, 12),
              bg='blue',
              fg='white').grid(row=35, column=95, pady=5)

        self.clear()
        self.update()
        self.winner()
        self.rect.mainloop()
Exemple #10
0
	def start(self):
		filename1 = PhotoImage(file = "1.png")
		filename2 = PhotoImage(file = "2.PNG")
		self.rect.create_image(200, 400, image=filename1)
		self.rect.create_image(980, 400, image=filename2)
		self.rect.pack(expand = YES, fill = BOTH)
#		self.rect.destroy()
		value=randint(10,30)
		self.turn=0
		self.countp=0
		self.countd=0
		self.val=value
#		self.rect.grid()
		
#		for i in range(0,200):
#			Label(self.frame, text="").grid(row=i,column=i)
		for i in range(0,200):
			Label(self.rect, text="",bg='blue').grid(row=i,column=i)
		
		Label(self.rect, text=value,font=(None,15),bg='white').grid(row=8,column=60)
		self.rect.grid()	
		self.rect.create_rectangle(178,442,212,586,fill='white')
		self.rect.create_rectangle(966,442,1002,586,fill='white')
		self.rect.create_rectangle(360,280,800,320,fill='white')
		self.rect.grid()
		self.rect.grid()

		self.e1 = Entry(self.rect)
		self.e1.grid(row=31, column=28)
		Button(self.rect, text='Pick',bg='orange',width=16,command=self.pick1).grid(row=30, column=28)
		Button(self.rect, text='Drop',bg='green',width=16,command=self.drop1).grid(row=32, column=28)
		Label(self.rect,text=self.n1,font=(None,15),bg='blue',fg='yellow').grid(row=34,column=28)
		
		self.e2 = Entry(self.rect)
		self.e2.grid(row=31, column=95)
		Button(self.rect, text='Pick',bg='orange',width=16,command=self.pick2).grid(row=30, column=95)
		Button(self.rect, text='Drop',bg='green',width=16,command=self.drop2).grid(row=32, column=95)
		Label(self.rect,text=self.n2,font=(None,15),bg='blue',fg='yellow').grid(row=34,column=95)
		
		self.p=value
		self.d=deque()
		s=[8,4,2,1,0]
		self.p1=MyStack()
		self.p2=MyStack()
		self.q=MyQueue()
		for j in range(0,5):	
			for i in s:
				self.d.insert_at_last(i)
		self.d.slices()
		self.d.shuffle()
		self.sum1=0
		self.sum2=0

		for i in range(0,5):
			self.d.slices()
			b1=self.d.remove_at_front()
			self.p1.push(b1)
			self.sum1+=b1
			b2=self.d.remove_at_last()
			self.p2.push(b2)
			self.sum2+=b2
		
		Label(self.rect,text=self.sum1,font=(None,12),bg='blue',fg='white').grid(row=35,column=28,pady=5)
		Label(self.rect,text=self.sum2,font=(None,12),bg='blue',fg='white').grid(row=35,column=95,pady=5)
	
		self.clear()
		self.update()
		self.winner()
		self.rect.mainloop()