Carleton University - SYSC 2006
insert_node_sorted()
Assignment 2 - Spring 2025The goal of insert_node_sorted() is to take a new node and insert it into an existing linked list of nodes in alphabetical order based on the node name.
For example, if your list already has:
nodeA -> nodeC -> nodeDand you insert nodeB, the result will be:
nodeA -> nodeB -> nodeC -> nodeDHow do we do this?
To insert a node alphabetically, we need to:
Compare Node Names:
Use
strcmp()to compare the new node’s name with existing nodes.
Insertion Scenarios:
Empty List: If the list is empty, insert the new node at the head.
Insert at Head: If the new node's name comes before the current head, insert it at the beginning.
Insert in Middle or End: Walk through the list and find the correct position for the new node.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 25 more lessons in Carleton University - SYSC 2006.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.