Lista senza interferenze

This commit is contained in:
orange 2016-12-27 18:08:16 +01:00
parent 215233df98
commit 7be287ed7f
2 changed files with 13 additions and 4 deletions

View File

@ -21,7 +21,7 @@ public class ListNI extends SimpleList{
else if(!isEmpty()){ else if(!isEmpty()){
Object headElem=head(); Object headElem=head();
remHead(); remHead();
remAt(pos-1, elem); remAt(pos-1);
addHead(headElem); addHead(headElem);
} }
} }

View File

@ -3,7 +3,8 @@ import java.util.Scanner;
public class Test{ public class Test{
public static void main(String [] args) throws Exception { public static void main(String [] args) throws Exception {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
SimpleList list = new SimpleList(); ListNI list = new ListNI();
ListNI list2;
System.out.println("Stringa: "); System.out.println("Stringa: ");
String line = sc.nextLine(); String line = sc.nextLine();
@ -14,12 +15,20 @@ public class Test{
line = sc.nextLine(); line = sc.nextLine();
} }
System.out.println("lunghezza lista: " + list.size()); list2=list.copy();
list2.addAt(3, "prova");
list.remAt(2);
while(!list.isEmpty()){ while(!list.isEmpty()){
line = (String) list.head(); line = (String) list.head();
System.out.println(line); System.out.print(line+" --> ");
list.remHead(); list.remHead();
} }
System.out.println();
while(!list2.isEmpty()){
line = (String) list2.head();
System.out.print(line+" --> ");
list2.remHead();
}
} }
} }