*EDIT* IT IS A SEGMENTATION FAULT NOT BUS ERROR (anyway to change thread title?)

I am trying to make a deep copy of a linked list, but whenever I run a test of the constructor i get a "Segmentation Fault". I tested the "Append" method and it works fine. I can't figure out why I am getting this error unless there is something wrong with "Append" though

Involved code:

Copy Contstructor:

List(const List &L){
       ListIterator p;         
       p.currentPtr=L.head;
       while(p.currentPtr->next!=L.head){
               p.currentPtr=p.currentPtr->next;
               this->Append(p.currentPtr->item); 
               listSize++;
               }          
               }  // copy constructor (*must* be a deep copy)

method Append:

void Append(int it){
            ListIterator p;
            p.currentPtr=this->head;
	     ListElement *temp= new ListElement();  
            temp->item=it;
		if(this->IsEmpty()){
                            this->head->next=temp;
				this->head->prev=temp;
				temp->next=this->head;
				temp->prev=this->head;   
                               }         
            else{ 
                    temp->next=p.currentPtr;
                    temp->prev=p.currentPtr->prev;
                    p.currentPtr->prev->next=temp;
                    p.currentPtr->prev=temp;
                    p.currentPtr=temp;
                    }
	 
                 listSize++;
}

Edited 7 Years Ago by .:Pudge:.: n/a

Out of curiosity are you taking cmps 260? We covered this recently.
I wish I could be of some solution I am just curious because I am trying to learn the same thing

Out of curiosity are you taking cmps 260? We covered this recently.
I wish I could be of some solution I am just curious because I am trying to learn the same thing

I am taking a Systems Programming course in which we work with C++

*also when i run the program in gdb it says that that line 7 of the second code block causes the error

Edited 7 Years Ago by .:Pudge:.: n/a

Hmm Ive never seen a double -> -> reference yet I am about on the same lesson you are. I couldn't tell you if it was right or not but id check it out

This article has been dead for over six months. Start a new discussion instead.