Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-1
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
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
Julian Komaromy
cb-1
Commits
129c0af0
Commit
129c0af0
authored
1 year ago
by
Julian Komaromy
Browse files
Options
Downloads
Patches
Plain Diff
pass tests
parent
0e36fb0b
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/stack.rs
+9
-10
9 additions, 10 deletions
src/stack.rs
src/syntax_tree.rs
+13
-5
13 additions, 5 deletions
src/syntax_tree.rs
with
22 additions
and
15 deletions
src/stack.rs
+
9
−
10
View file @
129c0af0
use
crate
::
Stack
;
// TODO Complete implementation
impl
Stack
for
Vec
<
i32
>
{
fn
init
()
->
Self
{
return
vec!
[]
Vec
::
new
()
}
fn
push_val
(
&
mut
self
,
i
:
i32
)
{
self
.push
(
i
)
self
.push
(
i
)
;
}
fn
top_val
(
&
self
)
->
Option
<&
i32
>
{
return
self
.last
()
self
.last
()
}
fn
pop_val
(
&
mut
self
)
->
Option
<
i32
>
{
return
self
.pop
()
self
.pop
()
}
fn
is_empty
(
&
self
)
->
bool
{
return
self
.is_empty
()
self
.is_empty
()
}
}
// Nil is only used for truly empty lists, nonempty lists end in Val(x, None)
#[derive(Debug)]
pub
enum
ListStack
{
Val
(
i32
,
Option
<
Box
<
ListStack
>>
),
...
...
@@ -48,28 +48,27 @@ impl Stack for ListStack {
fn
top_val
(
&
self
)
->
Option
<&
i32
>
{
match
self
{
Val
(
val
,
_o
)
=>
Some
(
val
),
Nil
=>
None
,
Nil
=>
None
}
}
fn
pop_val
(
&
mut
self
)
->
Option
<
i32
>
{
match
self
{
Val
(
value
,
other
)
=>
{
let
popped_value
=
*
value
;
match
other
.take
()
{
None
=>
*
self
=
Nil
,
Some
(
other
)
=>
*
self
=
*
other
,
};
Some
(
popped_value
)
}
Nil
=>
None
,
Nil
=>
None
}
}
fn
is_empty
(
&
self
)
->
bool
{
match
self
{
Val
(
_v
,
_o
)
=>
false
,
Nil
=>
true
,
_
=>
false
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/syntax_tree.rs
+
13
−
5
View file @
129c0af0
...
...
@@ -23,12 +23,12 @@ fn next_id() -> ID {
impl
<
T
>
SyntaxTree
<
T
>
{
/// Create a SyntaxTree with a root node that carries the given value
pub
fn
new
(
value
:
T
)
->
SyntaxTree
<
T
>
{
todo!
()
SyntaxTree
{
id
:
next_id
(),
value
,
children
:
Vec
::
new
()
}
}
/// Add another SyntaxTree as last child of this tree
pub
fn
push_node
(
&
mut
self
,
new_node
:
SyntaxTree
<
T
>
)
{
todo!
()
self
.children
.push
(
new_node
);
}
/// Create a new SyntaxTree with a root node that carries the given value. Add the created tree
...
...
@@ -39,7 +39,7 @@ impl<T> SyntaxTree<T> {
/// Add another SyntaxTree as first child of this tree
pub
fn
prepend_node
(
&
mut
self
,
new_node
:
SyntaxTree
<
T
>
)
{
todo!
()
self
.children
.insert
(
0
,
new_node
);
}
/// Create a new SyntaxTree with a root node that carries the given value. Add the created tree
...
...
@@ -66,7 +66,15 @@ impl<T> SyntaxTree<T> {
if
predicate
(
self
)
{
Some
(
self
)
}
else
{
todo!
()
for
child
in
self
.children
.iter
()
{
match
child
.find_node
(
predicate
)
{
None
=>
continue
,
some
=>
return
some
}
}
// nothing was found in any of the children
None
}
}
...
...
@@ -77,7 +85,7 @@ impl<T> SyntaxTree<T> {
&
mut
self
,
predicate
:
fn
(
&
SyntaxTree
<
T
>
)
->
bool
,
)
->
Option
<&
SyntaxTree
<
T
>>
{
todo!
(
)
self
.find_node
(
predicate
)
}
/// Return a reference to the value carried by the root of this tree
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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