View difference between Paste ID: KMjn3THv and BLyCJJyv
SHOW: | | - or go back to the newest paste.
1
public class ListaOrdLC {//costruisce una Lista ordinata
2
	private Elemento primo = null;
3
	private int num; //numero di elementi di ogni singola Lista
4
5
	public boolean isEmpty() {
6
	if (primo==null) return true;
7
	else return false;
8
	}
9
10
	public void insordine(String nome){//inserisce in ordine un nome
11
12
	Elemento tmp = primo;
13
	Elemento prec= null;
14
15
	if(isEmpty()){//se è vuota si aggiunge in testa
16
	Elemento target = new Elemento();
17
	target.info = nome;
18
	target.next = null;
19
	primo = target;
20
	}
21
	else {//se non è vuota si trova la posizione corretta e si inserisce
22
	while (tmp= null && att.info.compareTo(nome)<=0) {
23
	prec = tmp;
24
	tmp = tmp.next;
25
	}
26
27
	Elemento target = new Elemento();
28
29
	target.info = nome;
30
	if(tmp==primo){	// il primo
31
		   	nuovo.next=primo;
32
			primo=nuovo;
33
		   }
34
		   else {	//centrale o ultimo
35
			nuovo.next=prec.next;
36
			prec.next=nuovo;
37
	   }//fine if
38
39
40
41
	private class Elemento {//nodo della lista concatenata
42
   	 	String info;
43
    		Elemento next;}
44
45
46
	public String toString(){
47
	String mex = "\n\nla lista contiene " + num+  " elementi\n" + "stampa degli elementi:\n";
48
49
	Elemento tmp=primo;
50
	if(primo == null) {//se la lista è vuota
51
		mex= mex + "lista vuota";
52
		}
53
		else{//altrimenti, se la lista ha elementi stamparli
54
55
	while (tmp!=null) {
56-
		System.out.println("la lisa contiene3");
56+
		System.out.println("CICLO INFINITOOOOOOOOOOOOO");
57
	mex = mex + tmp.info + "\n";
58
	tmp = tmp.next;
59
	}
60
}//else
61
62
63
64
	return mex +"\n\n";
65
	}
66
}//fine ListaOrdLC