Skip to content

Instantly share code, notes, and snippets.

@pietroluongo
Last active June 27, 2019 22:41
Show Gist options
  • Save pietroluongo/885a6c3885ca8a49b6770704e54d2ca5 to your computer and use it in GitHub Desktop.
Save pietroluongo/885a6c3885ca8a49b6770704e54d2ca5 to your computer and use it in GitHub Desktop.

Revisions

  1. pietroluongo revised this gist Jun 27, 2019. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions lista2.hs
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,15 @@ buscar x (Node a l r)
    | x < a = buscar x l
    | x > a = buscar x r

    data Fila a = Empty | Fila a (Fila a) deriving (Show)

    type No = Int
    type Adj b = [(b, No)]
    type Contexto a b = (Adj b, No, a, Adj b)
    data Grafo a b = Vazio | Conectado (Contexto a b) (Grafo a b) deriving(Show)
    vazia :: Fila a
    vazia = Empty


    -- inserir :: (Maybe a) => a -> Fila a -> Fila a
    insereInicio a Empty = Fila (a) (Empty)
    insereInicio a (Fila x y) = Fila (a) (Fila x y)

    insereFinal a Empty = Fila (Empty) (a)
    insereFinal a (Fila x y) = Fila (Fila x y) a
  2. pietroluongo revised this gist Jun 27, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions lista2.hs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    -- Monads https://medium.com/@julianoalves/functors-applicatives-e-monads-explicados-com-desenhos-2c45d5db7d25
    data Arv a = Vazia | Node a (Arv a) (Arv a) deriving (Eq, Show, Read)

    instance Functor Arv where
  3. pietroluongo revised this gist Jun 27, 2019. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion lista2.hs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    data Arv a = Vazia | Node a (Arv a) (Arv a) deriving (Eq, Show, Read)

    instance Functor Arv where
    fmap f Vazia = Vazia
    fmap f (Node a l r) = Node (f a) (fmap f l) (fmap f r)

    singleton :: a -> Arv a
    singleton a = Node a Vazia Vazia

    @@ -18,4 +22,10 @@ buscar _ Vazia = False
    buscar x (Node a l r)
    | x == a = True
    | x < a = buscar x l
    | x > a = buscar x r
    | x > a = buscar x r


    type No = Int
    type Adj b = [(b, No)]
    type Contexto a b = (Adj b, No, a, Adj b)
    data Grafo a b = Vazio | Conectado (Contexto a b) (Grafo a b) deriving(Show)
  4. pietroluongo revised this gist Jun 27, 2019. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion lista2.hs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,21 @@
    data Arv a = Vazia | Node a (Arv a) (Arv a) deriving (Eq, Show)
    data Arv a = Vazia | Node a (Arv a) (Arv a) deriving (Eq, Show, Read)

    singleton :: a -> Arv a
    singleton a = Node a Vazia Vazia

    insere :: (Ord a) => a -> Arv a -> Arv a
    insere x Vazia = singleton x
    insere x (Node a l r)
    | x == a = Node x l r
    | x < a = Node a (insere x l) r
    | x > a = Node a l (insere x r)

    criar :: (Ord a) => [a] -> Arv a
    criar xs = foldr insere Vazia xs

    buscar :: (Ord a) => a -> Arv a -> Bool
    buscar _ Vazia = False
    buscar x (Node a l r)
    | x == a = True
    | x < a = buscar x l
    | x > a = buscar x r
  5. pietroluongo created this gist Jun 27, 2019.
    3 changes: 3 additions & 0 deletions lista2.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    data Arv a = Vazia | Node a (Arv a) (Arv a) deriving (Eq, Show)