Skip to content

Instantly share code, notes, and snippets.

@naufalnibros
Created June 27, 2022 05:00
Show Gist options
  • Select an option

  • Save naufalnibros/cee627819173e675fccaf7bc494847b1 to your computer and use it in GitHub Desktop.

Select an option

Save naufalnibros/cee627819173e675fccaf7bc494847b1 to your computer and use it in GitHub Desktop.
Struktur Data Set dalam Java
class SetClass {
int size = 0;
private final Object[] mapping = new Object[4];
void add(Object value) {
if (value == null) {
mapping[size] = "null";
} else {
mapping[size] = value;
}
size++;
}
boolean isEmpty() {
return size == 0;
}
boolean contains(Object value) {
for (int i = 0; i < size; i++) {
if (value == null) {
if (find(i).equals("null")) {
return true;
}
} else {
if (find(i).equals(value)) {
return true;
}
}
}
return false;
}
Object find(int index) {
return mapping[index];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment