Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ohj2
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
Show more breadcrumbs
mvholmsy
ohj2
Commits
c4b33cd2
Commit
c4b33cd2
authored
5 years ago
by
mvholmsy
Browse files
Options
Downloads
Patches
Plain Diff
Jäsenet -tietorakenne päivitetty dynaamiseksi, eli kasvattaa itseään
parent
6bc14f82
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
src/Tietorakenteet/Jasenet.java
+8
-2
8 additions, 2 deletions
src/Tietorakenteet/Jasenet.java
with
8 additions
and
2 deletions
src/Tietorakenteet/Jasenet.java
+
8
−
2
View file @
c4b33cd2
...
@@ -6,7 +6,7 @@ package Tietorakenteet;
...
@@ -6,7 +6,7 @@ package Tietorakenteet;
* Hiihtorekisterin jasenet, joka lisää ja poistaa jäseniä.
* Hiihtorekisterin jasenet, joka lisää ja poistaa jäseniä.
*/
*/
public
class
Jasenet
{
public
class
Jasenet
{
private
static
final
int
MAX_JASENIA
=
10
;
private
static
int
MAX_JASENIA
=
5
;
private
int
lkm
=
0
;
private
int
lkm
=
0
;
private
String
tiedostonNimi
=
""
;
private
String
tiedostonNimi
=
""
;
private
Jasen
alkiot
[]
=
new
Jasen
[
MAX_JASENIA
];
private
Jasen
alkiot
[]
=
new
Jasen
[
MAX_JASENIA
];
...
@@ -47,8 +47,13 @@ public class Jasenet {
...
@@ -47,8 +47,13 @@ public class Jasenet {
*/
*/
public
void
lisaa
(
Jasen
jasen
)
throws
SailoException
{
public
void
lisaa
(
Jasen
jasen
)
throws
SailoException
{
if
(
lkm
>=
alkiot
.
length
)
throw
new
SailoException
(
"Liikaa alkioita"
);
if
(
lkm
>=
alkiot
.
length
)
throw
new
SailoException
(
"Liikaa alkioita"
);
// TODO jos taulukko on täynnä, tehdään uusi taulukko,
Jasen
uusi
[]
=
new
Jasen
[
MAX_JASENIA
+
5
];
for
(
int
i
=
0
;
i
<
alkiot
.
length
;
i
++)
{
uusi
[
i
]
=
alkiot
[
i
];
}
alkiot
=
uusi
;
alkiot
[
lkm
]
=
jasen
;
alkiot
[
lkm
]
=
jasen
;
//jasenisto.add(jasen);
lkm
++;
lkm
++;
}
}
...
@@ -60,6 +65,7 @@ public class Jasenet {
...
@@ -60,6 +65,7 @@ public class Jasenet {
* @throws IndexOutOfBoundsException jos i ei ole sallitulla alueella
* @throws IndexOutOfBoundsException jos i ei ole sallitulla alueella
*/
*/
public
Jasen
anna
(
int
i
)
throws
IndexOutOfBoundsException
{
public
Jasen
anna
(
int
i
)
throws
IndexOutOfBoundsException
{
if
(
i
<
0
||
lkm
<=
i
)
if
(
i
<
0
||
lkm
<=
i
)
throw
new
IndexOutOfBoundsException
(
"Laiton indeksi: "
+
i
);
throw
new
IndexOutOfBoundsException
(
"Laiton indeksi: "
+
i
);
return
alkiot
[
i
];
return
alkiot
[
i
];
...
...
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