Implement a Algorithm to verify if the link list is in Ascending order?
A: template
bool linklist::isAscending() const{
nodeptr ptr = head;
while (ptr->_next)
{
if(ptr->_data > ptr->_next->_data)
return false;
ptr= ptr->_next;
}
return true;
}
Q: Write down an algorithm to reverse a link list?
A: template
void linklist::reverselist()
{
nodeptr ptr= head;
nodeptr nextptr= ptr->_next;
while(nextptr)
{
nodeptr temp = nextptr->_next;
nextptr->_next = ptr;
ptr = nextptr;
nextptr = temp;
}
head->_next = 0;
head = ptr;
}