void PointerFIFO::put(void* val) { ListNode *node = allocate(); node->data(val); node->next(NULL); if (mTail!=NULL) mTail->next(node); mTail=node; if (mHead==NULL) mHead=node; mSize++; }
void PointerFIFO::push_front(void* val) // by pat { // Pat added this routine for completeness, but never used or tested. // The first person to use this routine should remove this assert. ListNode *node = allocate(); node->data(val); node->next(mHead); mHead = node; if (!mTail) mTail=node; mSize++; }
//尾部扩充 void CPPList::append(int number){ ListNode * newNode = new ListNode(); newNode->data() = number; if (is_empty()) { ListHeader = newNode; ListEnd = newNode; } else { ListEnd->next = newNode; ListEnd = ListEnd->next; } newNode->next = ListTrailer; _size++; }
void CPPList::insert(ListNode *current, int number){ if (!is_empty()){ //do not insert if the list is empty ListNode *tmp = new ListNode; tmp->data() = number; if (current == ListHeader) { tmp->next = current; ListHeader = tmp; } else { tmp->next = current; findPreNode(current)->next = tmp; } _size++; } }