Answer to Question #227452 in C++ for Sandile

Question #227452
You have an ordered linked list with 5 object of type person in it.
Explain with an example of how to add and delete a person in an ordered linked list. Your list
should remain ordered after the insertion and after the deletion of the item.
Note: a Person in this case should be an object that has a name, surname, age and gender.
1
Expert's answer
2021-08-19T03:22:10-0400

Adding a Person in an Ordered Linked List

The best approach to use add a person in a linked list is a brute force method.

As the linked list is ordered, a loop can be used to traverse the link and check if the linked list person is greater than the given person. If this is true, the given person should be inserted at that position.

For example:

If the Linked List is ordered by the person age, to insert a new person into the Linked List, just traverse the list. If the person age in the List is greater, insert the new person into that position.

Deleting a Person in an Ordered Linked List.




If the person to be deleted is the first person, remove it. If the person to be deleted is in the middle, put a pointer to the previous person to that person to be deleted. Therefore, if the keys are not 0, a loop key-1 is executed to get a pointer to the previous person.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS