
Untitled
By: a guest on Feb 9th, 2010 | syntax:
C++ | size: 1.23 KB | hits: 35 | expires: Never
template<class T>
SAList<T>::SAList(const SAList<T> &right)
{
Node<T> *current;
Node<T> *previous;
head = new Node<T>(right.head->data_);
current = right.head->next_;
while(current != NULL) {
Node<T>* temp = new Node<T>(current->data_);
if(head->next_ == NULL){
head->next_ = temp;
temp->prev_ = head;
previous = temp;
}
else{
temp->prev_ = previous;
previous->next_ = temp;
previous = temp;
}
current = current->next_;
}
}
template <class T>
SAList<T>& SAList<T>::operator= (SAList<T> &right){
Node<T> *cur;
Node<T> *temp;
Node<T> *add;
cur = right.head;
while(cur != NULL)
{
add=new Node<T>(cur->data_);
if(this->head==NULL)
{
head = add;
add->prev_ = tail;
cur = cur->next_;
temp = head;
}
else
{
// if(cur->next_==right.tail)
{
temp->next_=add;
add->prev_=temp;
tail=temp;
temp=temp->next_;
cur=cur->next_;
}
if(temp->next_==NULL)
{
temp->next_=add;
add->prev_=temp;
temp=temp->next_;
cur=cur->next_;
}
}
}
return *this;
}