Skip to content

Instantly share code, notes, and snippets.

@dbc2201
Created January 16, 2019 06:16
Show Gist options
  • Save dbc2201/7987a0ba4c55d726c67963f2d0444a83 to your computer and use it in GitHub Desktop.
Save dbc2201/7987a0ba4c55d726c67963f2d0444a83 to your computer and use it in GitHub Desktop.
Code for List ADT in class 2F
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