could this code be the reason why the first element of the list is added to the end of the list when the MAX_FRIEND th element is added to a list?
what do i need to add to fix it

    // Keep looping so long as a new friend is not added to both users
    while ((f1_added == 0 || f2_added == 0) && count < MAX_FRIENDS) {
        if (friend1->friends[count] == NULL && f1_added == 0) {
            friend1->friends[count] = friend2;
            f1_added = 1;     // Track that friend2 was added to friend1's friendlist

        }
        if (friend2->friends[count] == NULL && f2_added == 0) {
            friend2->friends[count] = friend1;
            f2_added = 1;  // Track that friend 1 was added to friend2's friendlist

        }
    }