Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-23wi
lectures
Commits
10098307
Commit
10098307
authored
2 years ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Code after lecture03
parent
55e80af8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
03/ArrayIntList.java
+54
-0
03/ArrayIntList.java
03/ArrayIntListClient.java
+9
-0
03/ArrayIntListClient.java
with
63 additions
and
0 deletions
+63
-0
03/ArrayIntList.java
0 → 100644
View file @
10098307
public
class
ArrayIntList
{
private
int
[]
data
;
private
int
size
;
// size vs. capacity
// current size = 0
// max size (capacity) = 10
public
ArrayIntList
()
{
this
.
data
=
new
int
[
10
];
this
.
size
=
0
;
}
//[1, 2, 3]
public
String
toString
()
{
String
elements
=
""
;
for
(
int
i
=
0
;
i
<
this
.
size
;
i
++)
{
elements
+=
this
.
data
[
i
]
+
", "
;
}
if
(
elements
.
length
()
>
0
)
{
elements
=
elements
.
substring
(
0
,
elements
.
length
()
-
2
);
}
return
"["
+
elements
+
"]"
;
}
public
void
add
(
int
elt
)
{
if
(
this
.
size
==
this
.
data
.
length
)
{
int
[]
newData
=
new
int
[
this
.
size
*
2
];
for
(
int
i
=
0
;
i
<
this
.
data
.
length
;
i
++)
{
newData
[
i
]
=
this
.
data
[
i
];
}
this
.
data
=
newData
;
}
this
.
data
[
size
]
=
elt
;
this
.
size
++;
}
/**
* Puts element at index idx, shifting over everything after to the right.
* @param idx
* @param element
* For example, idx = 2, element = 42
* [1, 2, 3, 4, 5]
* ^
* [1, 2, 42, 3, 4, 5]
*/
public
void
add
(
int
idx
,
int
element
)
{
}
public
int
get
(
int
idx
)
{
return
-
1
;
}
}
This diff is collapsed.
Click to expand it.
03/ArrayIntListClient.java
0 → 100644
View file @
10098307
public
class
ArrayIntListClient
{
public
static
void
main
(
String
[]
args
)
{
ArrayIntList
list
=
new
ArrayIntList
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
list
.
add
(
i
);
}
System
.
out
.
println
(
list
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment