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.
Comments
Leave a comment