The code loops through requesting patient information including first name, last name, and patient ID. It allocates memory for a new patient item, inserts the information into it, and inserts the new item into a linked list in alphabetical order by last name. It displays the patient information in alphabetical order once complete.