255 views
4 4 votes

A singly linked list is:

$\texttt{5 -> 8 -> 20 -> 9 -> 20 -> 7 -> NULL}$

The function $\texttt{deleteByValue(L, val)}$ removes only the first node whose data is equal to $\texttt{val}$. It adjusts links and frees the removed node.

After calling:

$\texttt{deleteByValue(L, 20);}$

what will be the final linked list?

  1. $\texttt{5 -> 8 -> 9 -> 20 -> 7 -> NULL}$
     
  2. $\texttt{5 -> 8 -> 9 -> 7 -> NULL}$
     
  3. $\texttt{8 -> 20 -> 9 -> 20 -> 7 -> NULL}$
     
  4. $\texttt{5 -> 8 -> 20 -> 9 -> 7 -> NULL}$

2 Answers

2 2 votes

Only the first node with value $\texttt{20}$ is deleted. The second $\texttt{20}$ remains in the list.

Final list:

$\texttt{5 -> 8 -> 9 -> 20 -> 7 -> NULL}$

Answer:
Position:
Show:

Related questions

5 5 votes
2 2 answers
343
343 views
GO Classes asked Jul 3
343 views
Consider the following singly linked list:$\texttt{12 - 18 - 25 - 31 - 44 - 57 - NULL}$Now, consider the following function:int Size(struct Node *list) { int count = 0; w...
5 5 votes
2 2 answers
309
309 views
GO Classes asked Jul 3
309 views
A singly linked list is:$\texttt{5 - 8 - 20 - NULL}$A new node $\texttt{​newP}$ contains data $9$. Pointer $\texttt{​prevP}$ points to the node containing $8$.The inserti...
7 7 votes
1 1 answer
479
479 views
GO Classes asked Jul 3
479 views
A sequence of $n$ elements is implemented in two ways:As a normal array with contiguous memory and no extra empty slot. As a singly linked list with only a $\texttt{head}...
6 6 votes
1 1 answer
255
255 views
GO Classes asked Jul 3
255 views
For a singly linked list storing only the head pointer, which of the following operations can be done in worst-case $O(1)$ time?Access the $i$-th element Modify the $i$-t...