Skip to content

Instantly share code, notes, and snippets.

@dbc2201
Created January 15, 2019 04:23
Show Gist options
  • Save dbc2201/dfbb45a78d69267b5146d67e901765a4 to your computer and use it in GitHub Desktop.
Save dbc2201/dfbb45a78d69267b5146d67e901765a4 to your computer and use it in GitHub Desktop.
Code for List ADT in class
package list;
public class DemoList
{
int[] list = new int[10];
public static void main(String[] args)
{
DemoList list1 = new DemoList();
}
void insertItem(int value)
{
for (int i = 0; i < list.length; i++)
{
if (list[i] == 0)
{
list[i] = value;
break;
}
}
}
void removeItem(int index)
{
int i = 0;
for (i = index ; i < list.length - 1 ; i++)
{
list[i] = list[i + 1];
}
list[list.length - 1] = 0;
// set the last element as 0
}
int isEmpty()
{
if (list[0] == 0)
{
return 1;
}
else
{
return 0;
}
}
int isFull()
{
if (list[list.length - 1] != 0)
{
return 1;
}
else
{
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment