Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
aa:lab:sol:3 [2025/10/19 15:45]
andreidarlau04 adt
aa:lab:sol:3 [2025/10/19 21:59] (current)
andreidarlau04 [Algebraic Data Types]
Line 104: Line 104:
 Aflam ca pentru un load factor de peste 1/2 (suntem aproape de capacitatea maxima) avem cost amortizat -1, iar 2 daca ne apropiem de injumatatire. Aflam ca pentru un load factor de peste 1/2 (suntem aproape de capacitatea maxima) avem cost amortizat -1, iar 2 daca ne apropiem de injumatatire.
  
-<note important>​In operatiile de analiza amortizata, noi luam drept cost amortizat costul operatiilor mai "​scumpe",​ neluand in calcul operatiile "​ieftine",​ deci ĉ<​sub>​i</​sub>​ = 2 in acest caz, nicidecum ​-1. </​note>​+<note important>​In operatiile de analiza amortizata, noi luam drept cost amortizat costul operatiilor mai "​scumpe",​ neluand in calcul operatiile "​ieftine",​ deci ĉ<​sub>​i</​sub>​ = 2 in acest caz, nu -1. </​note>​
  
 2. Cazul stergerii in care capacitatea se schimba: 2. Cazul stergerii in care capacitatea se schimba:
Line 148: Line 148:
 Reverse(Void) = Void Reverse(Void) = Void
 Reverse(Cons(x,​ L)) = Append(Reverse(L),​ Cons(x, Void)) Reverse(Cons(x,​ L)) = Append(Reverse(L),​ Cons(x, Void))
 +</​code>​
 +Helper:
 +<​code>​
 +isNull(Void) = True
 +isNull(Cons(x,​ L)) = False
 </​code>​ </​code>​
  
 3. 3.
 <​code>​ <​code>​
 +bool isNull(List l) {
 +    return l == NULL;
 +}
 +
 int size(List l) { int size(List l) {
-    if (l == NULL)+    if (isNull(l))
         return 0;         return 0;
     return 1 + size(l->​next);​     return 1 + size(l->​next);​
Line 159: Line 168:
  
 List add(List l, int x) { List add(List l, int x) {
-    if (l == NULL)+    if isNull(l))
         return Cons(x, Void());         return Cons(x, Void());
     return Cons(l->​e,​ add(l->​next,​ x));     return Cons(l->​e,​ add(l->​next,​ x));
Line 165: Line 174:
  
 List append(List l1, List l2) { List append(List l1, List l2) {
-    if (l1 == NULL)+    if (isNull(l1))
         return l2;         return l2;
     return Cons(l1->​e,​ append(l1->​next,​ l2));     return Cons(l1->​e,​ append(l1->​next,​ l2));
Line 171: Line 180:
  
 List reverse(List l) { List reverse(List l) {
-    if (l == NULL)+    if (isNull(l))
         return Void();         return Void();
     return append(reverse(l->​next),​ Cons(l->​e,​ Void()));     return append(reverse(l->​next),​ Cons(l->​e,​ Void()));
 } }
 </​code>​ </​code>​