Q: Vector addition operator is not working correctly I have created 3 vectors where vector 3 is supposed to be the sum of the values of vector 1 and vector 2. Each element in the vectors consists of value, position, and a pointer to the next element. Vector 3 is not adding the values correctly and I cannot figure out what the issue is. Any help would be immensely appreciated - I have attached the code snippets below.
Cheers 
class element {
public:
    int value;
    int position;
    element * next;
    element() {
        next = nullptr;
    }
    element(int i, int j) {
        value = i;
        position = j;
        next = nullptr;
    }
};

class my_vector {
public:
    int size;
    int num_elements;
    element * head;
    my_vector() {
        num_elements = 0;
        head = nullptr;
    }
    my_vector operator + (my_vector v);
    void print();
    void add_element(int v, int p);
    void input();
};

void my_vector::add_element(int v, int p) {
    element * x;
    x = new element(v, p);
    x - > next = head;
    head = x;
}

void my_vector::input() {
    cout << "Enter number of elements" << endl;
    int num, v, p;
    cin >> num;
    cout << "Enter elements in value position pairs" << endl;
    for (int i = 0; i < num; i++) {
        cin >> v >> p;
        add_element(v, p);
    }
}

my_vector my_vector::operator + (my_vector v) {
    my_vector temp; // Vector 3
    element * p1 = head;
    element * p2 = v.head;

    while (p1 && p2 != nullptr) {

        if (p1 - > position == p2 - > position) {
            int ps = p1 - > position;
            int sum = p1 - > value + p2 - > value;
            temp.add_element(sum, ps);
            p1 = p1 - > next;
            p1 = p2 - > next;
        }

        if (p1 - > position != p2 - > position) {

            if (p1 - > position > p2 - > position) {
                int vs = p2 - > value;
                int pst = p2 - > position;
                temp.add_element(vs, pst);
                num_elements++;
                p2 = p2 - > next;
            }

            if (p2 - > position > p1 - > position) {
                int vs = p1 - > value;
                int pst = p1 - > position;
                temp.add_element(vs, pst);
                num_elements++;
                p1 = p1 - > next;
            }
        }
    }
    return temp;
}

int main() {
    my_vector v1, v2, v3;
    v1.input();
    v2.input();
    v3 = v1 + v2;
    return 0;
}

