Skip to content
Snippets Groups Projects
Commit 68e0759d authored by Heyd's avatar Heyd
Browse files

Supprimer P4a

parent c78be5d8
No related merge requests found
Showing
with 0 additions and 508 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="Common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
<?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>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=15
package PersonalStructure;
import defaultpackage.Structure;
public class ChainedList implements Structure {
protected Link head;
protected Cursor cursor;
protected int nbVal;
public ChainedList(Link head, Cursor cursor) {
this.head = head;
this.cursor = cursor;
this.nbVal = 1;
}
public ChainedList(Cursor cursor) {
this.cursor = cursor;
this.cursor.setList(this);
this.nbVal = 0;
}
public void setNextLink(Link currentLink)
{
Link last_next = this.cursor.currentLink.next;
this.cursor.currentLink.next = currentLink;
nbVal+=1;
}
public void setPreviousLink(Link currentLink)
{
Link last_next = this.cursor.currentLink.next;
this.cursor.currentLink.next = currentLink;
nbVal+=1;
}
public Link getLink()
{
return this.cursor.currentLink;
}
public Cursor getCursor()
{
return this.cursor;
}
public Link getNextLink()
{
return this.cursor.currentLink.next;
}
public Link getPreviousLink()
{
return this.cursor.currentLink.next;
}
public void replaceCursor(int position)
{
this.cursor.position(position);
}
public boolean isEmpty() {
boolean res = false;
if(this.nbVal != 0)
res = true;
return res;
}
@Override
public void Add(int value) {
if (nbVal == 0) {
Link new_link = new Link(value);
this.head = new_link;
this.head.last = new_link;
this.cursor.currentLink = new_link;
this.head.next = new_link;
}
else {
System.out.println("val = " + value);
this.replaceCursor(this.nbVal);
Link last_before_added = this.cursor.currentLink.last;
Link next_after_added = this.head;
Link new_link = new Link(value, next_after_added, last_before_added);
last_before_added.next = new_link;
this.head.last = new_link;
this.cursor.currentLink = new_link;
}
this.nbVal += 1;
System.out.println("nbVal = " + this.nbVal);
}
@Override
public void Remove(int index) throws Exception {
if ((index < 0) && isEmpty())
throw new IndexOutOfBoundsException("Wrong position");
this.replaceCursor(index);
Link last_of_remove = this.cursor.currentLink.last;
Link next_of_remove = this.cursor.currentLink.next;
last_of_remove.next = next_of_remove;
next_of_remove.last = last_of_remove;
this.cursor.currentLink = next_of_remove;
}
@Override
public int Select(int index) throws Exception {
if ((index < 0) && isEmpty())
throw new IndexOutOfBoundsException("Wrong position");
this.replaceCursor(index);
return this.cursor.currentLink.value;
}
}
package PersonalStructure;
public class Cursor {
protected Link currentLink;
protected ChainedList currentList;
protected int pos;
public Cursor(ChainedList currentList, Link currentLink, int pos) {
this.currentLink = currentLink;
this.currentList = currentList;
this.pos = pos;
}
public Cursor() {
this.pos = 0;
}
public void position(int pos)
{
// si on est arrivé à la bonne position, on garde le maillon actuel
if (pos == this.pos)
{ }
// si nous sommes avant la position voulue, on avance
else if (pos > this.pos)
{
while(pos != this.pos)
{
goForward();
}
}
// si nous sommes après la position voulue, on recule
else if (pos < this.pos)
{
while(pos != this.pos)
{
goBack();
}
}
}
private void goForward() {
// si on n'est pas encore arrivé à la fin de la liste, on avance
if(this.pos <= this.currentList.nbVal)
{
this.pos += 1;
this.currentLink = this.currentLink.next;
}
// sinon on retourne au début de la liste
else {
this.pos = 0;
this.currentLink = this.currentList.head;
}
}
private void goBack() {
// si on n'est pas encore arrivé au début de la liste, on recule
if(this.pos >= 0)
{
this.pos -= 1;
}
// sinon on va à la fin de la liste
else {
this.pos = this.currentList.nbVal;
}
// on recule toujours
this.currentLink = this.currentLink.last;
}
public void setList(ChainedList list) {
this.currentList = list;
this.currentLink = list.head;
}
}
package PersonalStructure;
public class Link {
protected int value;
protected Link next;
protected Link last;
public Link(int value, Link next, Link last) {
this.value = value;
this.next = next;
this.last = next;
}
public Link(int value) {
this.value = value;
}
public void setNext(Link next) {
this.next = next;
}
public void setLast(Link last) {
this.last = last;
}
}
package StandardStructure;
import defaultpackage.Structure;
import java.util.ArrayList;
import java.util.Random;;
public class ArrayListC implements Structure
{
protected ArrayList<Integer> arrayList;
public ArrayListC(int nbValue)
{
Random rnd = new Random();
arrayList = new ArrayList<Integer>();
for(int i = 0; i < nbValue; i++)
{
Add(rnd.nextInt());
}
}
@Override
public void Add(int value)
{
arrayList.add(value);
}
@Override
public void Remove(int index) throws Exception
{
try
{
arrayList.remove(index);
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
@Override
public int Select(int index) throws Exception
{
try
{
return arrayList.get(index);
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
}
package StandardStructure;
import java.util.LinkedList;
import java.util.Random;
import defaultpackage.Structure;
public class LinkedListC implements Structure
{
protected LinkedList<Integer> linkedList;
public LinkedListC(int nbValue)
{
Random rnd = new Random();
linkedList = new LinkedList<Integer>();
for(int i = 0; i < nbValue; i++) {
Add(rnd.nextInt());
}
}
@Override
public void Add(int value) {
// TODO Auto-generated method stub
linkedList.add(value);
}
@Override
public void Remove(int index) throws Exception {
// TODO Auto-generated method stub
try
{
linkedList.remove(index);
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
@Override
public int Select(int index) throws Exception
{
// TODO Auto-generated method stub
try
{
return linkedList.get(index);
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
}
package StandardStructure;
import java.util.Random;
import defaultpackage.Structure;
public class Table implements Structure
{
protected Integer[] tab;
public Table(int nbValue)
{
System.out.println("ajout d'une valeur");
Random rnd = new Random();
tab = new Integer[nbValue];
for(int i = 0; i < nbValue ; i++)
{
tab[i] = rnd.nextInt();
}
}
@Override
public void Add(int value) {
// TODO Auto-generated method stub
Integer[] temp = new Integer[tab.length + 1];
for(int i = 0; i < tab.length; i++) {
temp[i] = tab[i];
}
temp[temp.length] = value;
tab = temp;
}
@Override
public void Remove(int index) throws Exception
{
// TODO Auto-generated method stub
try
{
tab[index] = null;
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
@Override
public int Select(int index) throws Exception
{
// TODO Auto-generated method stub
try
{
return tab[index];
}
catch(IndexOutOfBoundsException e)
{
throw new Exception("L'index dfini ne se situe pas dans les bornes du tableau");
}
}
}
package defaultpackage;
import java.math.BigInteger;
import java.util.Random;
import PersonalStructure.ChainedList;
import PersonalStructure.Cursor;
import StandardStructure.ArrayListC;
import StandardStructure.LinkedListC;
import StandardStructure.Table;
public class Main {
public static void main(String[] args) {
System.out.println("Je suis ici");
// TODO Auto-generated method stub
GenerateTab(args[0], Integer.parseInt(args[1]));
//GenerateTab("Maillon", 1000000);
}
public static void GenerateTab(String type, int nbValue)
{
System.out.println("Je rentre : " + type);
if(type.equals("Tableau"))
{
Table tab = new Table(nbValue);
System.out.println("appeler");
}
if(type.equals("Array")) {
ArrayListC array = new ArrayListC(nbValue);
}
if(type.equals("Linked")) {
LinkedListC linked = new LinkedListC(nbValue);
}
if(type.equals("Maillon")) {
Cursor cursor = new Cursor();
ChainedList maillons = new ChainedList(cursor);
Random rnd = new Random();
for(int i = 0; i < nbValue; i++) {
maillons.Add(rnd.nextInt());
}
}
}
}
package defaultpackage;
public interface Structure
{
public void Add(int value);
public void Remove(int index) throws Exception;
public int Select(int index) throws Exception;
}
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
Manifest-Version: 1.0
Main-Class: defaultpackage.Main
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment