Exemplo n.º 1
0
    def partition(self, ll, value):
        head = ll.head
        before = before_head = Node(0)
        after = after_head = Node(0)
        while head:
            # If the original list node is lesser than the given x,
            # assign it to the before list.
            if head.value < value:
                before.next = head
                before = before.next
            else:
                # If the original list node is greater or equal to the given x,
                # assign it to the after list.
                after.next = head
                after = after.next

            # move ahead in the original list
            head = head.next

            # Last node of "after" list would also be ending node of the reformed list
        after.next = None
        # Once all the nodes are correctly assigned to the two lists,
        # combine them to form a single list which would be returned.
        before.next = after_head.next
        newll = LinkedList()
        newll.head = before_head.next
        return newll
    def addItem(self,key):
        hashKey = self.hashFunction(key)

        if self.table[hashKey] == None:
            self.table[hashKey] = LinkedList()
        self.table[hashKey].push(key)

        return hashKey
Exemplo n.º 3
0
    def sumoflinkedList(self, lla, llb):
        n1 = lla.head
        n2 = llb.head
        carry = 0
        ll = LinkedList()
        while n1 or n2:
            result = carry
            if n1 is not None:
                result += n1.value
                n1 = n1.next
            if n2 is not None:
                result += n2.value
                n2 = n2.next
            ll.add(int(result % 10))
            carry = result / 10

        return ll
Exemplo n.º 4
0
    def getIntersection(self,lla,llb):
        if lla.tail is not llb.tail:
            return False
        lenA = LinkedList.len(lla)
        lenB = LinkedList.len(llb)

        shorter = lla if lenA < lenB else llb
        longer = llb if lenB > lenA else lla

        diff = LinkedList.len(longer) - LinkedList.len(shorter)
        shorter = shorter.head
        longer = longer.head
        for i in range(diff):
            longer = longer.next

        while shorter != longer:
            shorter = shorter.next
            longer = longer.next

        return shorter.value
Exemplo n.º 5
0
    def render(self, lista=LinkedList(), idsLista=0):
        idDespesas = idsLista

        # Opções do módulo das despesas financeiras:
        opDespesas = "0"
        while opDespesas != "4":
            os.system("cls")
            TelaDespesas.headerDespesas()
            self.listar(lista)
            TelaDespesas.menuDespesas()
            TelaDespesas.footerDespesas()
            opDespesas = input(" Digite uma opção (1..4): ")

            # Opção para inserir dados na lista encadeada:
            if opDespesas == "1":
                valor, id = self.adicionarDados(idDespesas)
                idDespesas = id
                print(" Despesa cadastrada com sucesso!")
                print()
                lista.append(valor)
                time.sleep(1)
                os.system("cls")
                TelaDespesas.headerDespesas()
                self.listar(lista)
                TelaDespesas.menuDespesas()
                TelaDespesas.footerDespesas()

            # Opção para remover dados da lista encadeada:
            if opDespesas == "2":
                print()
                valor = int(input(" Digite o código a ser excluído: "))
                resultado = self.deleteItem(lista, valor)
                lista.remove(resultado)
                os.system("cls")
                TelaDespesas.headerDespesas()
                self.listar(lista)
                TelaDespesas.menuDespesas()
                TelaDespesas.footerDespesas()

            # Opções para gerar arquivo em PDF a partir dos dados da lista encadeda:
            if opDespesas == "3":
                print(" Gerar pdf...")
        return lista, idDespesas
Exemplo n.º 6
0
                before = before.next
            else:
                # If the original list node is greater or equal to the given x,
                # assign it to the after list.
                after.next = head
                after = after.next

            # move ahead in the original list
            head = head.next

            # Last node of "after" list would also be ending node of the reformed list
        after.next = None
        # Once all the nodes are correctly assigned to the two lists,
        # combine them to form a single list which would be returned.
        before.next = after_head.next
        newll = LinkedList()
        newll.head = before_head.next
        return newll


if __name__ == '__main__':
    part = Partition()
    ll = LinkedList()
    ll.add(5)
    ll.add(2)
    ll.add(3)
    ll.add(1)
    ll.add(4)
    print(ll)
    print(part.partition(ll, 3))
Exemplo n.º 7
0
 def __init__(self):
     listaDespesa = LinkedList()
Exemplo n.º 8
0
        longer = llb if lenB > lenA else lla

        diff = LinkedList.len(longer) - LinkedList.len(shorter)
        shorter = shorter.head
        longer = longer.head
        for i in range(diff):
            longer = longer.next

        while shorter != longer:
            shorter = shorter.next
            longer = longer.next

        return shorter.value

if __name__ == '__main__':
    ll = LinkedList()
    ll.head = Node(1)
    ll.head.next = Node(2)
    ll.head.next.next = Node(3)
    ll.head.next.next.next = Node(4)

    ll1 = LinkedList()
    ll1.head = Node(1)
    ll1.head.next = Node(2)
    ll1.head.next.next = Node(2)
    ll1.head.next.next.next = ll.head.next.next

    print(ll)
    print(ll1)

    i = Intersection()
Exemplo n.º 9
0
                if tempNode.next.value in visited:
                    tempNode.next = tempNode.next.next
                else:
                    visited.add(tempNode.next.value)
                    tempNode = tempNode.next
            return ll

    def removeDups1(self, ll):
        if ll.head is None:
            print("The list is empty.")
        else:
            tempNode = ll.head
            while tempNode:
                runner = tempNode
                while runner.next:
                    if tempNode.value == runner.next.value:
                        runner.next = runner.next.next
                    else:
                        runner = runner.next
                tempNode = tempNode.next
        return ll


if __name__ == '__main__':
    rd = RemoveDups()
    ll = LinkedList()
    ll.generate(10, 0, 6)
    print(ll)
    rd.removeDups1(ll)
    print(ll)
 def __init__(self):
     self.listaGeral = LinkedList()
Exemplo n.º 11
0
        n1 = lla.head
        n2 = llb.head
        carry = 0
        ll = LinkedList()
        while n1 or n2:
            result = carry
            if n1 is not None:
                result += n1.value
                n1 = n1.next
            if n2 is not None:
                result += n2.value
                n2 = n2.next
            ll.add(int(result % 10))
            carry = result / 10

        return ll


if __name__ == '__main__':
    s = SumOfLinkedLists()
    lla = LinkedList()
    lla.add(7)
    lla.add(1)
    lla.add(6)
    llb = LinkedList()
    llb.add(5)
    llb.add(9)
    llb.add(2)

    print(s.sumoflinkedList(lla, llb))
from telas.TelaHome import TelaHome
from telas.TelaReceitas import TelaReceitas
from telas.TelaDespesas import TelaDespesas
from telas.TelaSaldo import TelaSaldo
from linkedList.LinkedList import LinkedList
from arvoreBinaria.ArvoreBinariaDeBusca import ArvoreBinariaDeBusca
from telas.TelaPesquisa import TelaPesquisa
import os

# Criando o código principal:
if __name__ == '__main__':

    # Instanciando classes:
    listaReceitas = LinkedList()
    listaDespesas = LinkedList()
    receita = TelaReceitas()
    despesas = TelaDespesas()
    saldo = TelaSaldo()
    idsReceitas = 0
    idsDespesas = 0

    # Opções do módulo principal:
    op_home = "0"
    while op_home != "5":
        os.system("cls")
        TelaHome.render()
        op_home = input(" Digite uma opção (1..5): ")

        # Opção referente a receitas financeiras:
        if op_home == "1":
            # Aplicação de lista encadeada: