Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scala2020
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
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quentin Leblanc
scala2020
Commits
8c67b131
Commit
8c67b131
authored
5 years ago
by
Quentin Leblanc
Browse files
Options
Downloads
Patches
Plain Diff
tp2
parent
6e40a7dc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TP2/build.sbt
+5
-0
5 additions, 0 deletions
TP2/build.sbt
TP2/src/main/scala/ch/hepia/tp2/Stack.scala
+42
-0
42 additions, 0 deletions
TP2/src/main/scala/ch/hepia/tp2/Stack.scala
src/main/scala/ch/hepia/tp2/Stack.scala
+5
-0
5 additions, 0 deletions
src/main/scala/ch/hepia/tp2/Stack.scala
with
52 additions
and
0 deletions
TP2/build.sbt
0 → 100644
+
5
−
0
View file @
8c67b131
name
:=
"scala2020"
version
:=
"0.1"
scalaVersion
:=
"2.13.1"
This diff is collapsed.
Click to expand it.
TP2/src/main/scala/ch/hepia/tp2/Stack.scala
0 → 100644
+
42
−
0
View file @
8c67b131
package
ch.hepia.tp2
import
java.util._
class
Stack
[
A
]
{
private
val
content
:
List
[
A
]
=
new
ArrayList
[
A
]
//Return true if Stack is Empty
def
isEmpty
:
Boolean
=
content
.
isEmpty
//return size of stack
def
size
:
Int
=
content
.
size
//stack an element on the stack
def
push
(
a
:
A
)
:
Unit
=
content
.
add
(
0
,
a
)
//Unstack an element and return it
def
pop
:
A
=
{
if
(
this
.
size
==
0
)
{
throw
new
NoSuchElementException
}
else
{
content
.
remove
(
0
)
}
}
//Swap the 2 first elements of the stack, do nothing if less than 1 element
def
swap
:
Unit
=
{
if
(
this
.
size
>
1
)
{
this
.
push
(
content
.
remove
(
1
))
}
}
override
def
toString
:
String
=
{
val
sb
:
StringBuilder
=
new
StringBuilder
sb
.
append
(
"["
)
this
.
content
.
forEach
((
e
)
=>
sb
.
append
(
e
).
append
(
", "
))
sb
.
append
(
"]"
)
sb
.
toString
}
}
This diff is collapsed.
Click to expand it.
src/main/scala/ch/hepia/tp2/Stack.scala
0 → 100644
+
5
−
0
View file @
8c67b131
package
ch.hepia.tp2
class
Stack
{
}
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