// temp as last, temp2 as the end-1
void addEnd (int v)
{ node *temp, *temp2; // Temporary pointers
// Reserve space for new node and fill it with data
temp->data_=v;
temp->next = NULL;
// Set up link to this node
if (start_ == NULL)
start_ = temp;
else
{ temp2 = start_;
while (temp2->next != NULL)
{
temp2 = temp2->next; // Move to next link in chain
}
temp2->next = temp;
}
}
// this function delete a element at the end of linklist in Kathy's Example
void removeEnd()
{ node *temp1, *temp2;
if (start_ != NULL)
{ temp1 = start_;
while (temp1->next != NULL)
{ temp2 = temp1;
temp1 = temp1->next;
}
delete temp1;
temp2->next = NULL;
}
Publish Post
}