core dumped

This commit is contained in:
HORVILLE 2022-10-21 16:11:26 +02:00
parent 714c782053
commit 768f122da4
7 changed files with 403 additions and 9 deletions

View File

@ -4,7 +4,11 @@
public class ChainLink<T> {
private T value;
private T next;
private ChainLink<T> next;
public ChainLink(T t) {
this.value = t;
}
public T getValue() {
return value;
@ -14,11 +18,11 @@ public class ChainLink<T> {
this.value = value;
}
public T getNext() {
public ChainLink<T> getNext() {
return next;
}
public void setNext(T next) {
public void setNext(ChainLink<T> next) {
this.next = next;
}
}

View File

@ -1,3 +1,123 @@
public class ListChain {
import java.util.*;
public class ListChain<E> implements Collection<E> {
ChainLink<E> firstElement;
ChainLink<E> lastElement;
@Override
public boolean add(E e) {
if (firstElement == null) {
firstElement = new ChainLink<E>(e);
lastElement = firstElement;
} else {
ChainLink<E> newElement = new ChainLink<E>(e);
lastElement.setNext(newElement);
lastElement = newElement;
}
return true;
}
@Override
public boolean addAll(Collection<? extends E> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public void clear() {
firstElement = null;
lastElement = null;
}
@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public Iterator<E> iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean remove(Object o) {
return false;
}
public boolean remove(int n) {
ChainLink<E> prev = firstElement;
for (int i = 0; i < n-1; i++) {
if (prev.getNext() != null) {
prev = prev.getNext();
} else {
return false;
}
}
ChainLink<E> toRemove = prev.getNext();
if (toRemove.getNext() == null) return false;
prev.setNext(toRemove.getNext());
toRemove = null;
return true;
}
public E get(int n) {
ChainLink<E> e = firstElement;
for (int i = 0; i < n; i++) {
if (e.getNext() != null) {
e = e.getNext();
}
}
return e.getValue();
}
@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}
@Override
public <T> T[] toArray(T[] a) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,28 @@
/**
* ChainLink
*/
public class ChainLink<T> {
private T value;
private ChainLink<T> next;
public ChainLink(T t) {
this.value = t;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public ChainLink<T> getNext() {
return next;
}
public void setNext(ChainLink<T> next) {
this.next = next;
}
}

View File

@ -0,0 +1,153 @@
import java.util.*;
public class ListChain<E> implements Collection<E> {
ChainLink<E> firstElement;
ChainLink<E> lastElement;
@Override
public boolean add(E e) {
if (firstElement == null) {
firstElement = new ChainLink<E>(e);
lastElement = firstElement;
} else {
ChainLink<E> newElement = new ChainLink<E>(e);
lastElement.setNext(newElement);
lastElement = newElement;
}
return true;
}
@Override
public boolean addAll(Collection<? extends E> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public void clear() {
firstElement = null;
lastElement = null;
}
@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public Iterator<E> iterator() {
Iterator<E> e = new Iterator<E>() {
ChainLink<E> firstE = firstElement;
@Override
public boolean hasNext() {
return firstE.getNext() != null;
}
@Override
public E next() {
E v = firstE.getValue();
firstE = firstE.getNext();
return v;
}
};
return e;
}
@Override
public boolean remove(Object o) {
return false;
}
public boolean remove(int n) {
ChainLink<E> prev = firstElement;
if (n == 0) {
firstElement = prev.getNext();
prev = null;
return true;
}
for (int i = 0; i < n-1; i++) {
if (prev.getNext() != null) {
prev = prev.getNext();
} else {
return false;
}
}
ChainLink<E> toRemove = prev.getNext();
if (toRemove.getNext() == null) return false;
prev.setNext(toRemove.getNext());
toRemove = null;
return true;
}
@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public int size() {
int count = 1;
if (firstElement == null) return 0;
ChainLink<E> c = firstElement;
while (c.getNext() != null) {
c = c.getNext();
count++;
}
return count;
}
@Override
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}
@Override
public <T> T[] toArray(T[] a) {
// TODO Auto-generated method stub
return null;
}
public E get(int n) {
ChainLink<E> e = firstElement;
for (int i = 0; i < n; i++) {
if (e.getNext() != null) {
e = e.getNext();
}
}
return e.getValue();
}
}

View File

@ -1,18 +1,17 @@
import javax.swing.JPanel;
import java.awt.*;
import java.util.LinkedList;
import java.util.Random;
public class LumPanel extends JPanel {
private LinkedList<Color> l;
private ListChain<Color> l;
int width = 30;
int offset = 30;
int height = 60;
int spacing = 5;
public LumPanel() {
l = new LinkedList<Color>();
l = new ListChain<Color>();
Random r = new Random();
for (int i = 0; i < 10; i++) {

View File

@ -1,6 +1,4 @@
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
/**
* Luminance

View File

@ -0,0 +1,92 @@
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
public class TableList<E> implements Collection<E> {
E[] table;
public TableList() {
table = (E[])new Object[5];
}
@Override
public boolean add(E e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean addAll(Collection<? extends E> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public Iterator<E> iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}
@Override
public <T> T[] toArray(T[] a) {
// TODO Auto-generated method stub
return null;
}
}