Question: This function adds a new element in the first position of the list. void addFirst ( Student studentData ) Pseudocode: Create a new dynamic NodeType
This function adds a new element in the first position of the list.
void addFirstStudent studentData
Pseudocode:
Create a new dynamic NodeType object called newNode
Copy the studentData into newNode.data
if isEmpty
make first to point newNode eg first newNode
make last to point newNode
else
make newNode.next to point first eg newNode.next first
make first to point newNode
endif
Increase size by
getFirst
This function returns the a copy of the first element in the list. If the list is empty, it throws an string as exception with the message "The list is empty".
Student getFirst const
Pseudocode:
if empty
throw string as exception
else
return copy of the element pointed by first
getLast
This function returns the a copy of the last element in the list. If the list is empty, it throws an string as exception with the message "The list is empty".
Student getLast const
Pseudocode:
if empty
throw string as exception
else
return copy of the element pointed by last
In the main
Create a Linked list object.
Create Student objects and add them to the list using addFirst.
Display the content of the list.
Retrieve the first element in the list using getFirst and display its information.
Retrieve the last element in the list using getLast and display its information.
Example of expected output
Linked list App!
Wendy Lawson
Peter Parker
Bruce Wayne
Clark Kent
First element: Wendy Lawson
Last element: Clark Kent
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
