✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Se considera crearea unei liste dinamice ordonata
function nod(x){
this.comtor=1;
this.x=x;
this.urmator=null;
}
function inserare(){
x=eval(prompt("val x",""));
fanion.x=x;
q1=inceput;
q2=inceput.urmator;
while(q2.x<x){
q1=q2;
q2=q1.urmator;
}
if((q2.x==x) && (q2!=fanion))
q2.contor++;
else {
p=new nod(x);
q1.urmator=p;
p.urmator=q2;
}
}
function afisare(){
s=""; q=inceput.urmator;
while(q!=fanion){
s+="q.x="+q.x+"<br>";
q=q.urmator;
}
document.write("Lista: <br>"+s);
}
inceput=new nod(0); fanion=new nod(0); inceput.urmator=fanion;
c=eval(prompt("1-inserare, 2-afisare",""));
while(c==1 || c==2){
if(c==1)
inserare();
else
afisare();
c=eval(prompt("1-inserare, 2-afisare",""));
}
Faceti asocierile (Inserarea unui nod nou):