diff --git a/DEV 3.2/TP03/Chaine/ChainLink.java b/DEV 3.2/TP03/Chaine/ChainLink.java index eec0104..f62d72c 100644 --- a/DEV 3.2/TP03/Chaine/ChainLink.java +++ b/DEV 3.2/TP03/Chaine/ChainLink.java @@ -4,7 +4,11 @@ public class ChainLink { private T value; - private T next; + private ChainLink next; + + public ChainLink(T t) { + this.value = t; + } public T getValue() { return value; @@ -14,11 +18,11 @@ public class ChainLink { this.value = value; } - public T getNext() { + public ChainLink getNext() { return next; } - public void setNext(T next) { + public void setNext(ChainLink next) { this.next = next; } } \ No newline at end of file diff --git a/DEV 3.2/TP03/Chaine/ListChain.java b/DEV 3.2/TP03/Chaine/ListChain.java index 9e5d7a3..97e09f3 100644 --- a/DEV 3.2/TP03/Chaine/ListChain.java +++ b/DEV 3.2/TP03/Chaine/ListChain.java @@ -1,3 +1,123 @@ -public class ListChain { +import java.util.*; + +public class ListChain implements Collection { + + ChainLink firstElement; + ChainLink lastElement; + + @Override + public boolean add(E e) { + if (firstElement == null) { + firstElement = new ChainLink(e); + lastElement = firstElement; + } else { + ChainLink newElement = new ChainLink(e); + lastElement.setNext(newElement); + lastElement = newElement; + } + + return true; + } + + @Override + public boolean addAll(Collection 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 iterator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean remove(Object o) { + return false; + } + + public boolean remove(int n) { + ChainLink prev = firstElement; + for (int i = 0; i < n-1; i++) { + if (prev.getNext() != null) { + prev = prev.getNext(); + } else { + return false; + } + } + + ChainLink toRemove = prev.getNext(); + if (toRemove.getNext() == null) return false; + prev.setNext(toRemove.getNext()); + toRemove = null; + + return true; + } + + public E get(int n) { + ChainLink 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[] toArray(T[] a) { + // TODO Auto-generated method stub + return null; + } + } diff --git a/DEV 3.2/TP03/Luminance/ChainLink.java b/DEV 3.2/TP03/Luminance/ChainLink.java new file mode 100644 index 0000000..f62d72c --- /dev/null +++ b/DEV 3.2/TP03/Luminance/ChainLink.java @@ -0,0 +1,28 @@ +/** + * ChainLink + */ +public class ChainLink { + + private T value; + private ChainLink next; + + public ChainLink(T t) { + this.value = t; + } + + public T getValue() { + return value; + } + + public void setValue(T value) { + this.value = value; + } + + public ChainLink getNext() { + return next; + } + + public void setNext(ChainLink next) { + this.next = next; + } +} \ No newline at end of file diff --git a/DEV 3.2/TP03/Luminance/ListChain.java b/DEV 3.2/TP03/Luminance/ListChain.java new file mode 100644 index 0000000..a6ea7a8 --- /dev/null +++ b/DEV 3.2/TP03/Luminance/ListChain.java @@ -0,0 +1,153 @@ +import java.util.*; + +public class ListChain implements Collection { + + ChainLink firstElement; + ChainLink lastElement; + + @Override + public boolean add(E e) { + if (firstElement == null) { + firstElement = new ChainLink(e); + lastElement = firstElement; + } else { + ChainLink newElement = new ChainLink(e); + lastElement.setNext(newElement); + lastElement = newElement; + } + + return true; + } + + @Override + public boolean addAll(Collection 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 iterator() { + + Iterator e = new Iterator() { + + ChainLink 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 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 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 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[] toArray(T[] a) { + // TODO Auto-generated method stub + return null; + } + + public E get(int n) { + ChainLink e = firstElement; + for (int i = 0; i < n; i++) { + if (e.getNext() != null) { + e = e.getNext(); + } + } + + return e.getValue(); + } + +} diff --git a/DEV 3.2/TP03/Luminance/LumPanel.java b/DEV 3.2/TP03/Luminance/LumPanel.java index 318133a..c4bd874 100644 --- a/DEV 3.2/TP03/Luminance/LumPanel.java +++ b/DEV 3.2/TP03/Luminance/LumPanel.java @@ -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 l; + private ListChain l; int width = 30; int offset = 30; int height = 60; int spacing = 5; public LumPanel() { - l = new LinkedList(); + l = new ListChain(); Random r = new Random(); for (int i = 0; i < 10; i++) { diff --git a/DEV 3.2/TP03/Luminance/Luminance.java b/DEV 3.2/TP03/Luminance/Luminance.java index c5c19e3..ab25c60 100644 --- a/DEV 3.2/TP03/Luminance/Luminance.java +++ b/DEV 3.2/TP03/Luminance/Luminance.java @@ -1,6 +1,4 @@ import javax.swing.JFrame; -import java.awt.*; -import java.awt.event.*; /** * Luminance diff --git a/DEV 3.2/TP03/Tableau/TableList.java b/DEV 3.2/TP03/Tableau/TableList.java new file mode 100644 index 0000000..77aa5fa --- /dev/null +++ b/DEV 3.2/TP03/Tableau/TableList.java @@ -0,0 +1,92 @@ +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.Iterator; + + +public class TableList implements Collection { + + 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 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 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[] toArray(T[] a) { + // TODO Auto-generated method stub + return null; + } + +}