Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
LARA
inox
Commits
c6ecee57
Commit
c6ecee57
authored
14 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
more better
parent
6fa8978c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/BinarySearchTree.scala
+36
-4
36 additions, 4 deletions
testcases/BinarySearchTree.scala
with
36 additions
and
4 deletions
testcases/BinarySearchTree.scala
+
36
−
4
View file @
c6ecee57
...
@@ -14,7 +14,8 @@ object BinarySearchTree {
...
@@ -14,7 +14,8 @@ object BinarySearchTree {
sealed
abstract
class
Triple
sealed
abstract
class
Triple
case
class
SortedTriple
(
min
:
Int
,
max
:
Int
,
sorted
:
Boolean
)
extends
Triple
case
class
SortedTriple
(
min
:
Int
,
max
:
Int
,
sorted
:
Boolean
)
extends
Triple
/* def isSorted(tree: Tree): SortedTriple = tree match {
/*
def isSorted(tree: Tree): SortedTriple = tree match {
case Leaf() => SortedTriple(None(), None(), true)
case Leaf() => SortedTriple(None(), None(), true)
case Node(l,v,r) => sorted(l) match {
case Node(l,v,r) => sorted(l) match {
case SortedTriple(minl,maxl,false) => SortedTriple(None(), None(), false)
case SortedTriple(minl,maxl,false) => SortedTriple(None(), None(), false)
...
@@ -52,9 +53,39 @@ object BinarySearchTree {
...
@@ -52,9 +53,39 @@ object BinarySearchTree {
case _ => SortedTriple(None(),None(),false)
case _ => SortedTriple(None(),None(),false)
}
}
}
}
}*/
}
}
*/
def
treeMin
(
tree
:
Node
)
:
Int
=
tree
match
{
case
Node
(
left
,
v
,
_
)
=>
left
match
{
case
Leaf
()
=>
v
case
n
@
Node
(
_
,
_
,
_
)
=>
treeMin
(
n
)
}
}
def
treeMax
(
tree
:
Node
)
:
Int
=
tree
match
{
case
Node
(
_
,
v
,
right
)
=>
right
match
{
case
Leaf
()
=>
v
case
n
@
Node
(
_
,
_
,
_
)
=>
treeMax
(
n
)
}
}
def
insert
(
tree
:
Tree
,
value
:
Int
)
:
Node
=
{
//require(isSorted(tree))
tree
match
{
case
Leaf
()
=>
Node
(
Leaf
(),
value
,
Leaf
())
case
n
@
Node
(
l
,
v
,
r
)
=>
if
(
v
<
value
)
{
Node
(
l
,
v
,
insert
(
r
,
value
))
}
else
if
(
v
>
value
)
{
Node
(
insert
(
l
,
value
),
v
,
r
)
}
else
{
n
}
}}
ensuring
(
contents
(
_
)
==
contents
(
tree
)
++
Set
(
value
))
def
insert
(
tree
:
Tree
,
value
:
Int
)
:
Node
=
(
tree
match
{
/*
def remove(tree: Tree, value: Int) : Node = (tree match {
case Leaf() => Node(Leaf(), value, Leaf())
case Leaf() => Node(Leaf(), value, Leaf())
case n @ Node(l, v, r) => if(v < value) {
case n @ Node(l, v, r) => if(v < value) {
Node(l, v, insert(r, value))
Node(l, v, insert(r, value))
...
@@ -63,7 +94,8 @@ object BinarySearchTree {
...
@@ -63,7 +94,8 @@ object BinarySearchTree {
} else {
} else {
n
n
}
}
})
ensuring
(
contents
(
_
)
==
contents
(
tree
)
++
Set
(
value
))
}) ensuring (contents(_) == contents(tree) -- Set(value))
*/
def
contains
(
tree
:
Tree
,
value
:
Int
)
:
Boolean
=
tree
match
{
def
contains
(
tree
:
Tree
,
value
:
Int
)
:
Boolean
=
tree
match
{
case
Leaf
()
=>
false
case
Leaf
()
=>
false
...
...
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