Question

1. What would happen if you execute the following code just before traversing a linked list?...

1. What would happen if you execute the following code just before traversing a linked list?

head.setNext(head);

2. 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. 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. What is the advantage of linked lists over arrays

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) It creates a loop which repeatedly points head node and other nodes in the list will be dead links as it cannot be reachable.

2) When you dequee first element will ve 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 woud 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.


In case of any doubts, please comment.

Add a comment
Know the answer?
Add Answer to:
1. What would happen if you execute the following code just before traversing a linked list?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (20 pts) What would happen if you execute the following code just before traversing a linked...

    (20 pts) What would happen if you execute the following code just before traversing a linked list? head.setNext(head); (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 (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,...

  • Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the...

    Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list. Node prev = head; Node curr = head. next; while(curr.next!=null) { if(prev.element > 3) { prev = curr; curr = curr.next; } else break; } head = prev.next; Question 3 options: 3 2 4 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT