Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ALP 1 Tutorium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jonahbeneb02
ALP 1 Tutorium
Commits
52a840a7
You need to sign in or sign up before continuing.
Verified
Commit
52a840a7
authored
1 year ago
by
jonahbeneb02
Browse files
Options
Downloads
Patches
Plain Diff
Add solutions
parent
30785153
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
10/Queue.hs
+35
-16
35 additions, 16 deletions
10/Queue.hs
10/tut10.hs
+19
-0
19 additions, 0 deletions
10/tut10.hs
with
54 additions
and
16 deletions
10/Queue.hs
+
35
−
16
View file @
52a840a7
{--
Funktionale Programmierung - Wintersemester 2022/2023
Vorlesung am 04.01.2023
Katharina Klost
module
Queue
(
Queue
(
F
),
enqueue
,
dequeue
,
isEmpty
,
hasElem
,
count
)
where
Verschiedene Implementierungen von Queues
--}
-- Typklasse für die Queue
class
Queuelike
s
where
{-
Voraussetzung: Keine
Ergebnis: Eine neue Queue in die das Element hinten eingefügt ist, ist geliefert
-}
enqueue
::
a
->
s
a
->
s
a
{-
Voraussetzung: Keine
Ergebnis: Wenn die Queue leer ist, ist Nothing geliefert, sonst Just ein Tupel
aus dem vordesten Element und der Queue ohne das vorderste Element
-}
dequeue
::
s
a
->
Maybe
(
a
,
s
a
)
{-
Voraussetzung: Keine
Ergebnis: Wenn die Queue leer ist, ist False geliefert, sonst ist True geliefert
-}
isEmpty
::
s
a
->
Bool
data
Queue
a
=
Q
[
a
]
[
a
]
deriving
Show
--(Q inp out) in die erste Liste werden die Element eingefügt, aus der zweiten Liste entfernt
hasElem
::
(
Eq
a
)
=>
a
->
s
a
->
Bool
count
::
(
Eq
a
)
=>
a
->
s
a
->
Int
data
Queue
a
=
F
[
a
]
[
a
]
deriving
Show
instance
Queuelike
Queue
where
enqueue
x
(
Q
inp
out
)
=
Q
(
x
:
inp
)
out
enqueue
x
(
F
inp
out
)
=
(
F
(
x
:
inp
)
out
)
dequeue
(
F
[]
[]
)
=
Nothing
dequeue
(
F
inp
[]
)
=
dequeue
(
F
[]
(
reverse
inp
))
dequeue
(
F
inp
(
x
:
out
))
=
Just
(
x
,
(
F
inp
out
))
isEmpty
(
F
[]
[]
)
=
True
isEmpty
_
=
False
dequeue
(
Q
[]
[]
)
=
Nothing
dequeue
(
Q
inp
[]
)
=
dequeue
(
Q
[]
(
reverse
inp
))
dequeue
(
Q
inp
(
x
:
out
))
=
Just
(
x
,
Q
inp
out
)
hasElem
::
(
Eq
a
)
=>
a
->
Queue
a
->
Bool
hasElem
e
(
F
inp
out
)
=
elem
e
inp
||
elem
e
out
isEmpty
(
Q
[]
[]
)
=
True
isEmpty
_
=
False
count
::
(
Eq
a
)
=>
a
->
Queue
a
->
Int
count
e
(
F
inp
out
)
=
count'
inp
+
count'
out
where
count'
xs
=
foldr
(
\
x
acc
->
if
x
==
e
then
acc
+
1
else
acc
)
0
xs
This diff is collapsed.
Click to expand it.
10/tut10.hs
0 → 100644
+
19
−
0
View file @
52a840a7
import
Queue
import
Data.Maybe
data
Produkt
=
Produkt
String
Int
deriving
Show
type
Einkaufswagen
=
[
Produkt
]
type
Schlange
=
Queue
Einkaufswagen
anstellen
::
Schlange
->
Einkaufswagen
->
Schlange
anstellen
schlange
wagen
=
enqueue
wagen
schlange
kassieren
::
Schlange
->
(
Int
,
Schlange
)
kassieren
schlange
=
(
preis
,
neueSchlange
)
where
leereSchlange
=
F
[]
[]
leererEinkaufswagen
=
[]
(
produkte
,
neueSchlange
)
=
fromMaybe
(
leererEinkaufswagen
,
leereSchlange
)
$
dequeue
schlange
preis
=
foldr
(
\
(
Produkt
_
preis
)
acc
->
acc
+
preis
)
0
produkte
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment