示例#1
0
bool LinkedList<T>:: removeFirstOccurrence(const T& x)
{
  Node<T> *current = m_head;

  for(; current != NULL; current = current->m_next)//
  {
    if(current->m_data == x)
    {
      if(current == m_head) {
        removeAtHead();
      } else if(current == m_tail) {
        removeAtTail();
      } else {
        Node<T> *temp = current->m_prev;
        temp->m_next = current->m_next;
        temp->m_next->m_prev = temp;
        delete current;
        m_size--;
     }
      
      return true;
    }
    
    //current = current->m_next;
  }
  return false;     
}
示例#2
0
void LinkedList<T>:: clear()
{
  while(m_head != NULL)
    removeAtHead();
  m_size = 0;
  m_head = NULL;
  m_tail = NULL;
}
示例#3
0
StackVal pop(Stack* stack) {
    StackVal val;

    if (numItemsInStack(stack) <= 0) {
        fprintf(stderr, "Attempted to pop from empty stack! Exiting...\n");
        exit(-1);
    }

    val = (StackVal) (stack->pList->pHead->data);
    removeAtHead(stack->pList);

    return val;
}