-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCola.hs
More file actions
33 lines (24 loc) · 725 Bytes
/
Cola.hs
File metadata and controls
33 lines (24 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Practica 4
-- 1.2
-- Rol Implementador
module Colas (Queue, emptyQ, queueQ, firstQ, isEmptyQ, deQueueQ)
where
data Queue a = Consq [a] deriving Show
-- funcion de acceso
dameLista :: Queue a -> [a]
dameLista (Consq [a]) = [a]
-- retorna una cola vacia
emptyQ :: Queue a
emptyQ = Consq []
-- agrega un elemento a la cola
queueQ :: Queue a -> a -> Queue a
queueQ q n = (Consq (n : dameLista q))
-- retorna el primer elemento de la cola
firstQ :: Queue a -> a
firstQ q = last (dameLista q)
-- pregunta si la cola esta vacia
isEmptyQ :: Queue a -> Bool
isEmptyQ q = null (dameLista q)
-- quita el primero elemento de la cola y devuelve el resto
deQueueQ :: Queue a -> Queue a
deQueueQ q = Consq (init (dameLista q))