Created
January 15, 2019 04:23
-
-
Save dbc2201/dfbb45a78d69267b5146d67e901765a4 to your computer and use it in GitHub Desktop.
Code for List ADT in class
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 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