def inend(self, data):
     n = self._head
     if n != None:
         while (n.next != None):
             n = n.next
         n.next = node(data)
         n.next.prev = n
     else:
         self._head = node(data)
Exemplo n.º 2
0
 def setproximajogada(self, linha, coluna):
     '''
     Set da proximo ligação na lista ligada com informações das coordenadas atuais
     :param linha: int com a coordenada correspondente a linha
     :param coluna: int com a coordenada correspondente a coluna
     '''
     proximo = node((linha, coluna), False, self.proximajogada)
     self.proximajogada.setnext(proximo)
     self.proximajogada = proximo
Exemplo n.º 3
0
 def prepararjogo(self):
     '''
     Função que calcula informações necessarias para o funcionamento do jogo
     a quando a iniciação de um novo tabuleiro
     :return:
     '''
     ocupadas = 0
     for i in range(self.linhas):
         for j in range(self.linhas):
             simbolo = self.tabuleiro[i][j]
             if simbolo in ["#", "X", "O"]:
                 ocupadas += 1
                 if self.proximajogada == None:
                     self.proximajogada = node((i, j), True)
                 else:
                     proximo = node((i, j), False, self.proximajogada)
                     self.proximajogada.setnext(proximo)
                     self.proximajogada = proximo
     self.livres = (self.linhas * self.colunas) - ocupadas
Exemplo n.º 4
0
    def set(self, key, value):
        node = self._get_sublist(key)

        # If first node at idx=i
        if not node.has_content:
            node.content = (key, value)
            return

        # If existing nodes at idx=i
        last = None
        while node is not None:
            if self._check_key(node, key):
                node.content = (key, value)
                return
            last = node
            node = node.next
        last.next = linkedlist.node((key, value))
Exemplo n.º 5
0
 def enqueue(self, data):
     if self._front == self._rear == None:
         self._front = self._rear = node(data)
         return
     self._rear.next = node(data)
     self._rear = self._rear.next
Exemplo n.º 6
0
 def push(self, data):
     n = node(data)
     n.next = self._top
     self._top = n
Exemplo n.º 7
0
 def push(self, element):
     self.head = linkedlist.node(element, self.head)
Exemplo n.º 8
0
from linkedlist import node, ll


def commonlist(first, second, cl):
    current1 = first.head
    prev1 = current1
    current2 = second.head
    prev2 = current2


node1 = node(1)
node2 = node(2)
node3 = node(5)
first = ll()
first.insert(node1)
first.insert(node2)
first.insert(node3)
node4 = node(2)
node5 = node(5)
node6 = node(7)
second = ll()
second.insert(node4)
second.insert(node5)
second.insert(node6)

cl = ll()
commonlist(first, second, cl)
cl.printlist()
Exemplo n.º 9
0
class Stack(object):
    def __init__(self, top=None):
        self.ll = linklist(top)

    def push(self, new_element):
        "Push (add) a new element onto the top of the stack"
        self.ll.insert_first(new_element)

    def pop(self):
        "Pop (remove) the first element off the top of the stack and return it"
        return self.ll.delete_first()


# Test cases
# Set up some Elements
e1 = node(1)
e2 = node(2)
e3 = node(3)
e4 = node(4)

# Start setting up a Stack
stack = Stack(e1)

# Test stack functionality
stack.push(e2)
stack.push(e3)
print(stack.pop().value)
print(stack.pop().value)
print(stack.pop().value)
print(stack.pop())
stack.push(e4)
Exemplo n.º 10
0
        prev = current
        current = nextnode
    link.head = prev


def add(link):
    cur = link.head
    if not cur:
        return
    while (cur):
        if (cur.data + 1) % 10 != 0:
            cur.data += 1
            break
        else:
            cur.data = 0
            cur = cur.next


node1 = node(1)
node2 = node(9)
node3 = node(6)
link = ll()
link.insert(node1)
link.insert(node2)
link.insert(node3)
rev = ll()
reverse(link)
add(link)
reverse(link)
link.printlist()
 def inbeg(self, data):
     n = node(data)
     n.next = self._head
     self._head = n
     if n.next != None:
         n.next.prev = n
Exemplo n.º 12
0
        if (current_first.data < current_second.data):
            current = current_first.data
            current_first = current_first.next
        else:
            current = current_second.data
            current_second = current_second.next
        mergedlist.insert(current)

    if (current_first is None):
        mergedlist.insert(current_second)
    if (current_second is None):
        mergedlist.insert(current_first.data)


firstNode = node(1)
secondNode = node(3)
thirdNode = node(10)
fourthNode = node(2)
fifthNode = node(4)
sixthNode = node(6)

firstlist = ll()
firstlist.insert(firstNode)
firstlist.insert(secondNode)

secondlist = ll()
secondlist.insert(fourthNode)
secondlist.insert(fifthNode)
secondlist.insert(sixthNode)
secondlist.insert(thirdNode)
Exemplo n.º 13
0
 def _get_sublist(self, key):
     idx = self._get_index(key)
     if self.data[idx] is None:
         self.data[idx] = linkedlist.node()
     return self.data[idx]