Created
January 16, 2019 06:16
-
-
Save dbc2201/7987a0ba4c55d726c67963f2d0444a83 to your computer and use it in GitHub Desktop.
Code for List ADT in class 2F
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package faltoo; | |
import java.util.Arrays; | |
public class Faltoo | |
{ | |
int[] list = new int[10]; | |
public static void main(String[] args) | |
{ | |
Faltoo l1 = new Faltoo(); | |
System.out.println(Arrays.toString(l1.list)); | |
for (int i = 0; i < 10; i++) | |
{ | |
l1.insert(42 + i); | |
} | |
l1.remove(0); | |
System.out.println(Arrays.toString(l1.list)); | |
} | |
void insert(int value) | |
{ | |
for (int i = 0; i < list.length; i++) | |
{ | |
if (list[i] == 0) | |
{ | |
list[i] = value; | |
break; | |
} | |
} | |
} | |
void remove(int index) | |
{ | |
for (int i = index; i < list.length - 1; i++) | |
{ | |
list[i] = list[i + 1]; | |
} | |
list[list.length - 1] = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment