Write a function named pop1
that takes an argument named list
, which is the head cell of a linked list, and removes the first normal cell (not the head cell), and returns the data contained in the cell. If there are no normal cells in the list (i.e. the list is empty), leave the list alone and return null
instead. Code to construct an example linked list in the form used in the tests is given below.
var tail = { next: null };
var cell2 = { data: 12, next: tail };
var cell1 = { data: 45: next: cell2 };
var head = { next: cell1 };