Hello community, I am currently a junior in college and have been delving into the topic of linked lists. I feel like I have a firm understanding of the theory, what they are and how they are useful, this project however has me stumped in some areas. Essentially, we are to take a linked list class and turn it into a linked lists class using headers and trailers, I understand what the headers and trailers are, I am just unsure as to how they improve the algorithm. As a result it has been frustratingly difficult to commence with the coding. Here is one function definition I am trying to improve with headers and trailers.
template <class Type>
void orderedLinkedList<Type>::insert(const Type& newItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
nodeType<Type> *newNode; //pointer to create a node
bool found;
newNode = new nodeType<Type>; //create the node
newNode->info = newItem; //store newItem in the node
newNode->link = NULL; //set the link field of the node
//to NULL
if (first == NULL) //Case 1
{
first = newNode;
last = newNode;
count++;
}
else
{
current = first;
found = false;
while (current != NULL && !found) //search the list
if (current->info >= newItem)
found = true;
else
{
trailCurrent = current;
current = current->link;
}
Any help at all would be very very much appreciated. Thanks so much for your time. Again, I really just need to see an example of how the algorithm would change, from what I understand it should be far more simplified, any point in the right direction would be immensely helpful.