Question

Onl. (a) i. What is a linear list? ii. Distinguish between linear list and circular linked list. (b) With the aid of diagrams

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

(a)

i. Linear linked list is a data structure where nodes are linked one by one. One node points to its next node and finally the last node points to null.

ii. As in the linear linked list last node points to null but in case of circular linked list "last" node points back to start of the list which makes it circular.

(b)

i. Maintain 2 pointers prev and curr.

curr

|

[1]->[2]->[3]-----------------[k-1]->[k]->[k+1]--------

Initially prev points to null and curr points to start of list.

prev curr

| |

[1]->[2]->[3]-----------------[k-1]->[k]->[k+1]--------

Then we start traversing list and keep going until curr points to kth element.

prev

|

[1]->[2]->[3]-----------------[k-1]->[k+1]--------

Now we just do prev.next = curr.next, this will remove curr node from list.

Then delete curr to free up space occupied by it.

ii. Maintain 1 pointer curr.

curr

|

[1]->[2]->[3]-----------------[k]->[k+1]--------

Initially points to head.

curr

|

[1]->[2]->[3]-----------------[k]->[k+1]--------

Traverse list till curr points to kth element.

curr

|

[1]->[2]->[3]-----------------[k]->[y]--------

Finally insert the node y next to curr i.e.

y.next = curr.next and curr.next = y.

Add a comment
Know the answer?
Add Answer to:
Onl. (a) i. What is a linear list? ii. Distinguish between linear list and circular linked list. (b) With the aid of...
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
  • C programming A linked list is a linear data structure that allows us to add and remove items fro...

    c programming A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. We have studied the doubly-linked, circular, with a dummy-header-node version of a linked list. In the class notes we studied several functions to manipulate a Linked List. For this assignment you must write the code for the following additional linked list functions: addFirst,...

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
Active Questions
ADVERTISEMENT