Question
Which one of the following code is for inserting a new cell in a doubly linked list? (not sorted) Select one: a. Function(Cell: input) Cell
Which one of the following code is for inserting a new cell in a doubly linked list? (not sorted)
Select one:
a. Function(Cell: input) Cell sentinel = new Cell() sentinel.Next = null input = input.Next While (input != null) Cell: next_cell = input input = input.Next Cell: after_me = sentinel While (after_me.Next != null) And (after_me.Next.Value < next_cell.Value) after_me = after_me.Next End While next_cell.Next = after_me.Next after_me.Next = next_cell End While return sentinel End Function
b. Function(Cell: top, Cell: new_cell) While (top.Next != null) And (top.Next.Value < new_cell.Value) top = top.Next End While new_cell.Next = top.Next top.Next = new_cell End Function
c. Function(Cell: after_me, Cell: new_cell) new_cell.Next = after_me.Next after_me.Next = new_cell new_cell.Next.Prev = new_cell new_cell.Prev = after_me End Function
d. Function(Cell: input) Cell: sentinel = new Cell sentinel.Next = null While (input.Next != null) Cell: best_after_me = input Integer: best_value = best_after_me.Next.Value Cell: after_me = input.Next While (after_me.Next != null) If (after_me.Next.Value > best_value) Then best_after_me = after_me best_value = after_me.Next.Value End If after_me = after_me.Next End While Cell: best_cell = best_after_me.Next best_after_me.Next = best_cell.Next best_cell.Next = sentinel.Next sentinel.Next = best_cell End While Return sentinel End Function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started