166k views
0 votes
Module 6 Assignment: This assignment is an individual assignment. 1. (20 pts) What would happen if you execute the following code just before traversing a linked list? head.setNext(head); 2. (20 pts) The linked list that follows represents a queue. If we dequeue once, what item is dequeued? (7, Ajay, NFL)(3, Sarah, Mario)(9, Jim, Golf)head (5, Joe, Sonic)null tail 3. (20 pts) The linked list that follows represents a stack. After we push the player (5,Joe,Sonic) onto the stack, what are the first and last items on the stack? (7, Ajay, NFL)(3, Sarah, Mario)(9, Jim, Golf)null head 4. (40 pts) What is the advantage of linked lists over arrays? Note:

1 Answer

2 votes

Answer:

Check the explanation

Step-by-step explanation:

1) It is expected to produce a loop which repeatedly points head node and other nodes in the list will be dead links as it can't be reachable.

2) When you dequee first element will have removed. That is 7, Ajay, NFL.

3) When you push an element, it will be added at the beginning. So first item would be new item that is 5,joe, sonic. Last item don't change it would be same 9,jim,Golf.

4)

1) Arrays are continuous. If you need to store 1000 elements and there are no 1000 continuous memory locations, then program will fails. But if memory contains sparsed 1000 locations, we can use linked list.

2) Insert, delete are faster in linked list than Array.

User Todd Christensen
by
6.7k points