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,...

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • 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...

  • Qn 1. A gaming company consists of many kind of games and each customer orders online to buy a ga...

    WRITE A C PROGRAM PLEASE WRITE COMMENTS EXPLAINING THE PROGRAM THANKS Qn 1. A gaming company consists of many kind of games and each customer orders online to buy a game. The gaming company will search for the specific game upon customers request in the order of first come first served basis. The gaming company has the following requirements. (10marks) 1. There are many kinds of games available (at least ten). They may have more than one game for each...

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
ADVERTISEMENT