Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Untitled

By: a guest on Feb 9th, 2010  |  syntax: C++  |  size: 1.23 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. template<class T>
  2. SAList<T>::SAList(const SAList<T> &right)
  3. {
  4.     Node<T> *current;
  5.     Node<T> *previous;
  6.     head = new Node<T>(right.head->data_);
  7.     current = right.head->next_;
  8.     while(current != NULL) {
  9.         Node<T>* temp = new Node<T>(current->data_);
  10.         if(head->next_ == NULL){
  11.             head->next_ = temp;
  12.             temp->prev_ = head;
  13.             previous = temp;
  14.         }
  15.         else{
  16.          temp->prev_ = previous;
  17.          previous->next_ = temp;
  18.          previous = temp;
  19.       }
  20.       current = current->next_;
  21.    }
  22. }
  23.  
  24. template <class T>
  25. SAList<T>& SAList<T>::operator= (SAList<T> &right){
  26.         Node<T> *cur;
  27.         Node<T> *temp;
  28.         Node<T> *add;
  29.  
  30.         cur = right.head;
  31.  
  32.         while(cur != NULL)
  33.         {
  34.                 add=new Node<T>(cur->data_);
  35.  
  36.                 if(this->head==NULL)
  37.                 {
  38.                         head = add;
  39.                         add->prev_ = tail;
  40.                         cur = cur->next_;
  41.                         temp = head;
  42.                 }
  43.                 else
  44.                 {
  45.         //              if(cur->next_==right.tail)
  46.                         {
  47.                                 temp->next_=add;
  48.                                 add->prev_=temp;
  49.                                 tail=temp;
  50.  
  51.                                 temp=temp->next_;
  52.                                 cur=cur->next_;
  53.                         }
  54.  
  55.                         if(temp->next_==NULL)
  56.                         {
  57.                                 temp->next_=add;
  58.                                 add->prev_=temp;
  59.  
  60.                                 temp=temp->next_;
  61.                                 cur=cur->next_;
  62.                         }
  63.                 }
  64.         }
  65.         return *this;
  66. }