CS140 -- Final Exam: Question 23 (8 points)

Suppose you have the following typedef for doubly-linked lists:
typedef struct dlist {
  struct dlist *flink;
  struct dlist *blink;
  Jval val;
} Dllist;
And suppose your doubly-linked lists are like in dllist.c -- circular both ways with a sentinel node.

On the answer sheet, circle all of the following implementations of delete_node() that successfully delete a specified node from a list:
a.
delete_node(Dllist *d)
{
  d->flink = NULL;
  d->blink = NULL;
  free(d);
}
b.
delete_node(Dllist *d)
{
  d->flink->blink = d->blink;
  d->flink->blink->flink = d->flink;
  free(d);
}
c.
delete_node(Dllist *d)
{
  if (d->is_sentinel) return;
  d->flink->blink = d->blink;
  d->blink->flink = d->flink;
  free(d);
}
d.
delete_node(Dllist *d)
{
  d->flink->blink = d->blink;
  d->blink->flink = d->flink;
  free(d);
}
e.
delete_node(Dllist *d)
{
  Dllist *back, *front;

  back = d->blink;
  front = d->flink;
  free(d);
  front->blink = back;
  back->flink = front;
}
f.
delete_node(Dllist *d)
{
  Dllist *back, *front;

  front = d->flink;
  back = d->blink;
  back->flink->blink = back;
  front->blink->flink = front;
  free(d);
}
g.
delete_node(Dllist *d)
{
  Dllist *back, *front;

  front = d->flink;
  back = d->blink;
  back->flink->flink->blink = back;
  front->blink->flink = front;
  free(d);
}