Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. In a linked list, the order of the elements is determined by the order in which the nodes were created to store the elements. b. In a linked list, memory allocated for the nodes is sequential. c. \(A\) single linked list can be traversed in either direction. d. In a linked list, nodes are always inserted either at the beginning or the end because a linked link is not a random-access data structure.

Problem 2

Describe the two typical components of a single linked list node.

Problem 3

What is the stored in the link field of the last node of a nonempty single linked list?

Problem 4

Suppose that first is a pointer to a linked list. What is stored in first?

Problem 14

Show what is produced by the following \(\mathrm{C}++\) code. Assume the node is in the usual info-link form with the info of type int. (list and ptr are pointers of type nodeType.) 1ist \(=\) new nodeType; \(1 \mathrm{ist} \rightarrow \mathrm{info}=20\) ptr \(=\) new nodeType; \(p t r->i n f 0=28\) \(p t r->1\) ink \(=N U L L\) 1 ist \(->\operatorname{link}=\) ptr ptr \(=\) new nodeType; \(p t r->i n f 0=30\) \(p t r->1\) ink \(=1\) ist list \(=\operatorname{ptr}\) ptr \(=\) new nodeType; \(p t r->i n f 0=42\) \(p t r->1 i n k=1 i s t->1 i n k\) \(1 i s t->1 i n k=p t r\) \(p t r=1\) ist while (ptr != NULL) $$\\{$$ $$\begin{array}{l} \text { cout }<<\operatorname{ptr} \rightarrow \inf _{0}<<\text { end } 1 ; \\\ \operatorname{ptr}=\operatorname{ptr} \rightarrow \operatorname{lin} \mathrm{k} ; \end{array}$$ $$\\}$$

Problem 15

Assume that the node of a linked list is in the usual info-link form with the info of type int. The following data, as described in parts (a) to (d), is to be inserted into an initially linked list: \(72,43,8,12 .\) Suppose that head is a pointer of type nodeType. After the linked list is created, head should point to the first node of the list. Declare additional variables as you need them. Write the \(\mathrm{C}++\) code to create the linked list. After the linked list is created, write a code to print the list. What is the output of your code? a. Insert 72 into an empty linked list. b. Insert 43 before 72 c. Insert 8 at the end of the list. d. Insert 12 after 43

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks