Segmentation Fault Error

Getting Segmentation Fault error when adding a second Linked List to an existing Linked List. Any ideas why the error is being caused?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
template<class ItemType>
LinkedList<ItemType> LinkedList<ItemType>::operator+(const LinkedList<ItemType> &right_hand_side) const {
  // If this list is empty return the other one.
  if (IsEmpty()) return right_hand_side;
  LinkedList<ItemType> new_list;//the new list
  Node<ItemType>* x;//left side
  Node<ItemType>* y;// right side
  x=front_ptr_;//points to left side linked list
  y=right_hand_side.front_ptr_;//points to right side linked list
  while(x->GetNext()!=nullptr)
{
   x=x->GetNext();
}
x->SetNext(y);//set right hand side at the end
new_list.front_ptr_=x.front_ptr_;

  return new_list;
}
Last edited on
This code looks fine to me, the problem is somewhere else
Topic archived. No new replies allowed.