Let L = {a₁, a₂, …, aₙ}, n ≥ 0, be a list whose Pascal representation is type…

PYQ GATE 1997

Let L = {a₁, a₂, …, aₙ}, n ≥ 0, be a list whose Pascal representation is

type list = record
  next: ^list;
  val: integer
end

The following function returns a list in which a₂ᵢ and a₂ᵢ₋₁, 1 ≤ i ≤ ⌊n/2⌋, are interchanged. Complete the function by filling the four boxes. Write the line number and the content of each box.

1.  function change(p: ^list): ^list;
2.  var q, t: ^list;
3.  begin
4.    if p = nil then change := p
5.    else if p^.next = nil then change := □
6.    else begin
7.      q := p^.next;
8.      □ := q;
9.      t := q^.next;
10.     □ := p;
11.     □ := change(t)
12.   end
13. end

Attempted by 2 students.

Sign up free to check your answer

Sign up free

Explore the full course: Data Structures

Loading lesson…