Assume that we have the following declarations: type SList = record N: integer ;
ID: 3830053 • Letter: A
Question
Assume that we have the following declarations:
type SList = record
N: integer;
Next: SList
end;
var q,r,s : SList;
T: SList;
Assume that the situation diagrammed below exists before each part of this problem:
Boxes with two slots are SLists. The top slot is the N field; the bottom is the Next field. Reference values are arrows; nil appears as a ground symbol. Undefined values are blank. For named variables, each name appears above the upper left corner. Diagram the final result of each of the following 16 sequences of assignments (a) - (p). Assume that the situation above is restored before each fragment. Up to three of the fragments are illegal; tell why for each. Note: We use a beta () in a prefix position to denote creation of a reference value.
4 2Explanation / Answer
a) q: q.next so pointing to 2 ..valid
b) also similar to above...valid
c) q|.next means 2 ..we are trying to assign q|.next|.next| means 4
so valid
d) r.next is 4 ..so valid
e) similar to above valid
f) this statement not valid ... it makes recursive loop which may have deadlock and
illegal. s->q abd q->s .... so not valid
g) s.next = s .. not valid self referenc or self loop
h) q = T --> so copying value , it is valid
i) q:= q.next.next.next connected to eart symbol, so exists and valid
j)s=r ==>a assigning value..so valid
k) r = B T ----> Referencing T value to r so valid
l) rederence of T is making q next, so valid
m) r.next = Br valid
n) valid
o) G is not defined. so not valid
p) q.next.N = s|.N valid