Implementato interamente un tda sequenze usando array (ArrayIndexList). Aggiunto reverse di sequenze in global.
This commit is contained in:
@@ -2,6 +2,8 @@ package com.xgiovio;
|
||||
|
||||
import arraylist.ArrayIndexList;
|
||||
import general_utility.test_object;
|
||||
import sequence.NodeSequence;
|
||||
import sequence.Sequence;
|
||||
import stack.NodeStack;
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,9 @@ public class ArrayIndexListTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
61
com/xgiovio/ArraySequenceTest.java
Normal file
61
com/xgiovio/ArraySequenceTest.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.xgiovio;
|
||||
|
||||
import arraylist.ArrayIndexList;
|
||||
import general_utility.test_object;
|
||||
import position.Position;
|
||||
import sequence.ArraySequence;
|
||||
import sequence.NodeSequence;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 23/03/14
|
||||
* Time: 20:37
|
||||
*/
|
||||
public class ArraySequenceTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArraySequence<test_object> a = new ArraySequence<test_object>(10);
|
||||
|
||||
a.add(0,new test_object(1));
|
||||
a.add(1,new test_object(2));
|
||||
a.add(2,new test_object(3));
|
||||
a.add(3,new test_object(4));
|
||||
|
||||
System.out.print(a);
|
||||
a.remove(2);
|
||||
System.out.print(a);
|
||||
System.out.print(a.first().element());
|
||||
System.out.print(a.last().element());
|
||||
a.addLast(new test_object(1000));
|
||||
System.out.print(a);
|
||||
a.addFirst(new test_object(2000));
|
||||
System.out.print(a);
|
||||
a.add(0,new test_object(1));
|
||||
System.out.print(a);
|
||||
a.add(5,new test_object(5));
|
||||
System.out.print(a);
|
||||
a.add(6,new test_object(125));
|
||||
System.out.print(a);
|
||||
a.add(8,new test_object(211));
|
||||
System.out.print(a);
|
||||
a.set(0, new test_object(211));
|
||||
System.out.print(a);
|
||||
a.set(1,new test_object(211));
|
||||
System.out.print(a);
|
||||
|
||||
|
||||
global.reverse(a);
|
||||
|
||||
System.out.print(a);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,6 +53,9 @@ public class NodeSequenceTest {
|
||||
a.set(6,new test_object(200));
|
||||
|
||||
System.out.print(a);
|
||||
global.reverse(a);
|
||||
|
||||
System.out.print(a);
|
||||
|
||||
|
||||
|
||||
|
||||
22
com/xgiovio/global.java
Normal file
22
com/xgiovio/global.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.xgiovio;
|
||||
|
||||
import sequence.Sequence;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 30/03/2014
|
||||
* Time: 21:35
|
||||
*/
|
||||
class global {
|
||||
public static <E > void reverse (Sequence<E> in){
|
||||
if (in.size()> 1){
|
||||
E t = in.removeFirst();
|
||||
global.reverse(in);
|
||||
in.addLast(t);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user