Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 443 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>P4A</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/p4a/
./*.class
\ No newline at end of file
package p4a;
import java.util.Arrays;
public class ArrayListPerso<E> implements Structure{
private E[] tableau;
private int nbElements;
private final static int taille_par_defaut = 10000;
private final static int incr_par_defaut = 2500;
public ArrayListPerso() {
tableau = (E[]) new Object[taille_par_defaut];
}
@Override
public void ajout(Object element, int position) {
E[] tab;
if (position < 0 || position > nbElements) {
throw new IndexOutOfBoundsException("ajout : mauvais index " + position);
}
if (nbElements >= tableau.length) {
tab = Arrays.copyOf(tableau, tableau.length + incr_par_defaut);
}
else {
tab = tableau;
}
for (int i = nbElements; i > position; i--) {
tab[i] = tab[i - 1];
}
tab[position] = (E) element;
tableau = tab;
nbElements++;
}
@Override
public void suppression(int position) {
if (position < 0 || position >= nbElements) {
throw new IndexOutOfBoundsException("suppression : position incorrecte " + position);
}
for (int i = position + 1; i < nbElements; i++) {
tableau[i - 1] = tableau[i];
}
nbElements--;
}
@Override
public Object acces(int position) {
if (position > tableau.length || position < 0) {
throw new IllegalArgumentException("acces : position incorecte");
}
return tableau[position];
}
}
package p4a;
import java.util.ArrayList;
public class ArrayListStd<E> extends ArrayList<E> implements Structure{
private ArrayList<E> liste;
public ArrayListStd()
{
liste = new ArrayList<E>();
}
@Override
public void ajout(Object element, int position) {
liste.add(position, (E) element);
}
@Override
public void suppression(int position) {
liste.remove(position);
}
@Override
public Object acces(int position) {
return liste.get(position);
}
}
package p4a;
public class LinkedListPerso<T> implements Structure
{
private static class Maillon<T>
{
private T val; // valeur du maillon
private Maillon<T> suivant; // reference au maillon suivant
private Maillon() // pour creer la sentinelle
{
val = null;
suivant = this;
}
private Maillon(T x, Maillon<T> succ)
{
val = x;
suivant = succ;
}
} // class Maillon
private class Curseur
{
private int pos; // position courante dans la liste
private Maillon<T> maillon; // maillon courant pointe
private Curseur()
{
pos = -1;
maillon = LinkedListPerso.this.sentinelle;
}
private void positionner(int pos)
{
if (!( pos >= -1 && pos <= longueur()))
throw new IllegalStateException(
"mauvaise position pos = " + pos + " ");
if (pos < this.pos)
{
this.pos = -1;
maillon = sentinelle;
}
while (this.pos < pos)
{
this.pos++;
maillon = maillon.suivant;
}
}
} // class Curseur
private Maillon<T> sentinelle;
private Curseur curs; // curseur specifique a ListeChainee
private int nbVal;
public LinkedListPerso()
{
sentinelle = new Maillon<T>() ;
curs = this.new Curseur();
nbVal = 0;
}
public int longueur()
{
return nbVal;
}
public boolean estVide()
{
return nbVal == 0;
}
@Override
public T acces(int pos)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos);
return curs.maillon.val;
}
public void remplacer(int pos, T x)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos) ;
curs.maillon.val = x;
}
@Override
public void ajout(Object element, int position)
{
if (!(position >= 0 && position <= nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(position));
curs.positionner(position - 1) ;
Maillon<T> pred = curs.maillon;
Maillon<T> succ = pred.suivant;
Maillon<T> nouveau = new Maillon<T>((T)element, succ);
pred.suivant = nouveau ;
nbVal++;
}
@Override
public void suppression(int pos)
{
if (!(pos >= 0 && pos < nbVal))
throw new IndexOutOfBoundsException(
String.valueOf(pos));
curs.positionner(pos - 1);
Maillon<T> pred = curs.maillon;
Maillon<T> aEnlever = pred.suivant;
Maillon<T> succ = aEnlever.suivant;
pred.suivant = succ;
nbVal--;
}
} // class ListeChainee
\ No newline at end of file
package p4a;
import java.util.LinkedList;
public class LinkedListStd<E> extends LinkedList<E> implements Structure {
private LinkedList<E> liste;
public LinkedListStd()
{
liste = new LinkedList<E>();
}
@Override
public void ajout(Object element, int position) {
liste.add(position, (E) element);
}
@Override
public void suppression(int position) {
liste.remove(position);
}
@Override
public Object acces(int position) {
return liste.get(position);
}
}
package p4a;
public class MainArrayListPersoAddDebut {
public static void main(String[] args) {
ArrayListPerso<Integer> arraylist = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arraylist.ajout(0, 0);
}
}
}
package p4a;
public class MainArrayListPersoAddFin {
public static void main(String[] args) {
ArrayListPerso<Integer> arraylist = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arraylist.ajout(0, i);
}
}
}
package p4a;
import java.util.Random;
public class MainArrayListPersoGet {
public static void main(String[] args) {
Random rnd = new Random();
ArrayListPerso<Integer> arrayList = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = 0; i < nbOperation; i++) {
arrayList.acces(rnd.nextInt(nbOperation));
}
}
}
package p4a;
public class MainArrayListPersoRemoveDecrementation {
public static void main(String[] args) {
ArrayListPerso<Integer> arrayList = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = nbOperation-1; i >= 0; i--) {
arrayList.suppression(i);
}
}
}
package p4a;
public class MainArrayListPersoRemoveFirstValue {
public static void main(String[] args) {
ArrayListPerso<Integer> arrayList = new ArrayListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = 0; i < nbOperation; i++) {
arrayList.suppression(0);
}
}
}
package p4a;
public class MainArrayListStdAddDebut {
public static void main(String[] args) {
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, 0);
}
}
}
package p4a;
public class MainArrayListStdAddFin {
public static void main(String[] args) {
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
}
}
package p4a;
import java.util.Random;
public class MainArrayListStdGet {
public static void main(String[] args) {
Random rnd = new Random();
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = 0; i < nbOperation; i++) {
arrayList.acces(rnd.nextInt(nbOperation));
}
}
}
package p4a;
public class MainArrayListStdGetCentre {
public static void main(String[] args) {
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = 0; i < nbOperation; i++) {
arrayList.acces((nbOperation/2)%2==0?nbOperation/2:(int)(nbOperation/2-0.5));
}
}
}
package p4a;
public class MainArrayListStdRemoveDecrementation {
public static void main(String[] args) {
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = nbOperation-1; i >= 0; i--) {
arrayList.suppression(i);
}
}
}
package p4a;
public class MainArrayListStdRemoveFirstValue {
public static void main(String[] args) {
ArrayListStd<Integer> arrayList = new ArrayListStd<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
arrayList.ajout(0, i);
}
for (int i = 0; i < nbOperation; i++) {
arrayList.suppression(0);
}
}
}
package p4a;
public class MainLinkedListPersoAddDebut {
public static void main(String[] args) {
LinkedListPerso<Integer> linkedList = new LinkedListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
linkedList.ajout(0, 0);
}
}
}
package p4a;
public class MainLinkedListPersoAddFin {
public static void main(String[] args) {
LinkedListPerso<Integer> linkedList = new LinkedListPerso<Integer>();
int nbOperation = Integer.parseInt(args[0]);
for (int i = 0; i < nbOperation; i++) {
linkedList.ajout(0, i);
}
}
}