File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,20 @@ public static void main(String[] args) {
5
5
Movies harrypotter = new Movies ("Harry Potter" , "Chris Columbus" , 2001 );
6
6
Movies starwars = new Movies ("Star Wars Episode 1" , "George Lucas" , 1999 );
7
7
Movies theInterview = new Movies ("The interview" , "Seth Rogen and James Franco" , 2014 );
8
+ Movies naruto = new Movies ("Naruto: The Last" , "Masashi Kishimoto" , 2018 );
9
+ Movies test = new Movies ("test" , "test" , 0 );
10
+
8
11
9
12
MoviesList movies = new MoviesList ();
10
13
11
14
movies .insertFirst (harrypotter );
12
15
movies .insertLast (starwars );
13
16
movies .insertLast (theInterview );
17
+ movies .insertLast (naruto );
18
+
19
+ movies .insertIn (test , 0 );
20
+
21
+ movies .deleteIn (3 );
14
22
15
23
for (int i = 0 ; i < movies .getSize (); i ++) {
16
24
System .out .println ("Name: " + movies .getMovie (i ).getName () +
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public void insertLast(Movies movie) {
46
46
47
47
@ Override
48
48
public void insertIn (Movies movie , int n ) {
49
- if (isEmpty ()) {
49
+ if (isEmpty () || n == 0 ) {
50
50
insertFirst (movie );
51
51
} else {
52
52
if (this .size == n ) {
@@ -55,7 +55,7 @@ public void insertIn(Movies movie, int n) {
55
55
Nodo newNodo = new Nodo (movie );
56
56
Nodo point = this .head ;
57
57
int count = 0 ;
58
- while (count < n && point .next != null ) {
58
+ while (count < ( n - 1 ) && point .next != null ) {
59
59
point = point .next ;
60
60
count ++;
61
61
}
@@ -97,7 +97,7 @@ public void deleteLast() {
97
97
@ Override
98
98
public void deleteIn (int n ) {
99
99
if (!isEmpty ()) {
100
- if (this .size == 1 || n == 1 ) {
100
+ if (this .size == 1 || n == 0 ) {
101
101
deleteFirst ();
102
102
} else if (this .size == n ) {
103
103
deleteLast ();
You can’t perform that action at this time.
0 commit comments