Exemple #1
0
def scan(data):
    "This method uses grahamScan to create a convex hull from the given points"
    hullX = myStack()  # For the X-coordinates of the hull
    hullY = myStack()  # For the Y-coordinates of the hull
    newPoints = []  # For storing the unused points
    newPoints.append([])  # For the X-coordinates
    newPoints.append([])  # For the Y-coordinates
    backTrackTracker = False
    hullX.stackPush(data[0].pop(0))
    hullY.stackPush(data[1].pop(0))
    '''First element of the data is always the starting point of the hull,
       which is the lowest y-coordinate we calculated
    '''
    M = 1  # This Stores the size of the hull stack
    while True:
        if backTrackTracker is not True:
            hullX.stackPush(data[0].pop(0))  # Pop the 1st item, add to hull
            hullY.stackPush(data[1].pop(0))  # Pop the 1st item, add to hull
            M += 1
        if len(data[0]) == 0:  # This is true when all points are serviced
            return hullX.fullStack(), hullY.fullStack(), newPoints
        if leftOrRight(hullX.atIndex(M - 2), hullY.atIndex(M - 2),
                       hullX.atIndex(M - 1), hullY.atIndex(M - 1), data[0][0],
                       data[1][0]) == 'left':
            backTrackTracker = False
        else:  # The points are collinear or makes a right turn
            # Backtracking
            newPoints[0].append(hullX.stackPop())
            newPoints[1].append(hullY.stackPop())
            backTrackTracker = True
            M -= 1
Exemple #2
0
    def add(self, item):
        if not self.stack1 or not self.stack2:
            self.stack1 = stack.myStack()
            self.stack2 = stack.myStack()

        while not self.stack2.isEmpty():
            self.stack1.pushNode(self.stack2.pop())

        self.stack1.push(item)

        while not self.stack1.isEmpty():
            self.stack2.pushNode(self.stack1.pop())
Exemple #3
0
 def push(self,item):
     stack.myStack.push(self,item)
     if not self.minStack:
         self.minStack=stack.myStack()
         self.minStack.push(item)
     else:
         if item < self.minStack.peek():
             self.minStack.push(item)
Exemple #4
0
def postFixConverter(expression):

    operators = ['+', '*', '-', '/', '(', ')']
    operands = ['a', 'b', 'c', 'd']
    operatorsStack = myStack()
    operandsStack = myStack()
    postFixString = ""
    for i in expression:
        if i in operators:
            operatorsStack.push(i)
        else:
            operandsStack.push(i)
            if (len(operandsStack.myList) == 2):
                postFixString = postFixString + operandsStack.myList[
                    0] + operandsStack.myList[1] + operatorsStack.myList[0]
                operandsStack.empty()

    print(operatorsStack.display())
    print(operandsStack.display())

    #operandsStack.empty()
    print(operandsStack.myList)
    print(operatorsStack.getLastElement())
    print(postFixString)
Exemple #5
0
def sortStack(unsorted):
    sorted = stack.myStack()
    if not unsorted or unsorted.isEmpty():
        return sorted
    while not unsorted.isEmpty():
        currNode = unsorted.pop()
        if sorted.isEmpty() or currNode.value <= sorted.peek():
            sorted.pushNode(currNode)
        else:
            count = 0
            while not sorted.isEmpty() and sorted.peek() < currNode.value:
                unsorted.pushNode(sorted.pop())
                count += 1
            sorted.pushNode(currNode)
            for i in range(count):
                sorted.pushNode(unsorted.pop())

    return sorted
Exemple #6
0
        if sorted.isEmpty() or currNode.value <= sorted.peek():
            sorted.pushNode(currNode)
        else:
            count = 0
            while not sorted.isEmpty() and sorted.peek() < currNode.value:
                unsorted.pushNode(sorted.pop())
                count += 1
            sorted.pushNode(currNode)
            for i in range(count):
                sorted.pushNode(unsorted.pop())

    return sorted


if __name__ == "__main__":
    mystack = stack.myStack()
    mystack.push(4)
    mystack.push(7)
    mystack.push(1)
    mystack.push(2)
    mystack.push(6)
    mystack.push(10)
    mystack.push(3)

    mysorted = sortStack(mystack)

    mystr = ""
    while not mysorted.isEmpty():
        mystr += str(mysorted.pop().value) + " "

    print(mystr)
Exemple #7
0
# import the library
from appJar import gui
import copy
import stack
import time
import sudoparser


#fields/variables
progress = 0
count = 0
empties = 0
runtime = 0
limit = 1000
oldboards = stack.myStack() #a list of board that will be used to save board states if brute forcing is necessary


# handle button events
def clear(button):
    app.disableButton("Clear")
    clearboard()
    app.enableButton("Clear")
            
def clearboard():
    global runtime
    app.setMeter("Status",99.0,"Clearing")
    app.clearAllEntries(callFunction=False)
    for row in range(0,9):
        for col in range (0,9):
            app.setEntryFg(str(row)+str(col),"Black")
Exemple #8
0
    def add(self, item):
        if not self.stackNewest or not self.stackOldest:
            self.stackNewest = stack.myStack()
            self.stackOldest = stack.myStack()

        self.stackNewest.push(item)