Creata unsorted position list

This commit is contained in:
2014-04-06 20:38:04 +02:00
parent c193420828
commit 7f3a0bfc24
4 changed files with 145 additions and 54 deletions

View File

@@ -16,42 +16,26 @@ import java.util.Iterator;
public class NodePositionListTest {
public static void main(String[] args) {
NodePositionList<test_object> a = new NodePositionList<test_object>();
NodePositionList<Integer> a = new NodePositionList<Integer>();
a.addLast(new test_object(1));
a.addLast(new test_object(2));
a.addLast(new test_object(3));
a.addLast(new test_object(4));
a.addLast(new Integer(1));
a.addLast(new Integer(1));
a.addLast(new Integer(1));
a.addLast(new Integer(2));
a.addLast(new Integer(2));
a.addLast(new Integer(2));
a.addLast(new Integer(3));
a.addLast(new Integer(4));
a.addLast(new Integer(4));
a.addLast(new Integer(4));
a.addLast(new Integer(4));
a.addLast(new Integer(4));
global.cancellaDuplicati(a);
System.out.print(a);
a.reverse();
System.out.print(a);
Iterator<test_object> it = a.iterator();
System.out.print(it.hasNext());
System.out.print(it.next());
System.out.print(it.hasNext());
System.out.print(it.next());
System.out.print(it.hasNext());
System.out.print(it.next());
System.out.print(it.hasNext());
System.out.print(it.next());
System.out.print(it.hasNext());
Iterator<Position<test_object>> itp = a.positions();
System.out.print(itp.hasNext());
System.out.print(itp.next().element());
System.out.print(itp.hasNext());
System.out.print(itp.next().element());
System.out.print(itp.hasNext());
System.out.print(itp.next().element());
System.out.print(itp.hasNext());
System.out.print(itp.next().element());
System.out.print(itp.hasNext());

View File

@@ -0,0 +1,52 @@
package com.xgiovio;
import priorityqueue.SortedListPriorityQueue;
import priorityqueue.UnsortedListPriorityQueue;
import java.security.InvalidKeyException;
/**
* Created with MONSTER.
* User: xgiovio
* Date: 02/04/2014
* Time: 00:10
*/
public class UnsortedListPriorityQueueTest {
public static void main(String[] args) throws InvalidKeyException{
UnsortedListPriorityQueue<Integer,String> a = new UnsortedListPriorityQueue<Integer, String>();
a.insert(5,"hello");
System.out.println(a.size());
System.out.println(a);
a.insert(11,"sdas");
System.out.println(a.size());
a.insert(21,"sdas");
a.insert(1,"sdas");
a.insert(-20,"slkjldas");
System.out.println(a);
System.out.println(a.size());
a.insert(21,"sdas");
a.insert(-34,"sdas");
a.insert(45,"slkjldas");
System.out.println(a);
System.out.println(a.size());
System.out.println(a.min());
System.out.println(a.size());
a.removeMin();
System.out.println(a.size());
System.out.println(a);
System.out.println(a.min());
a.removeMin();
System.out.println(a);
System.out.println(a.size());
System.out.println(a.min());
}
}

View File

@@ -1,7 +1,12 @@
package com.xgiovio;
import position.Position;
import position.PositionList;
import sequence.Sequence;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Created with MONSTER.
* User: xgiovio
@@ -19,4 +24,35 @@ class global {
}
public static void cancellaDuplicati (PositionList<Integer>L){
if (L.size() >=2){
Position<Integer> first;
Position<Integer> second;
first = L.first();
second = L.next(first);
for (;true;) {
if (first.element().equals(second.element())) {
L.remove(second);
if (first!= L.last()) {
second = L.next(first);
}else {
break;
}
} else {
first = second;
if (first!= L.last()) {
second = L.next(second);
}else {
break;
}
}
}
}
}
}