The same elements shall be identified when the single link list is removed.



  • There's a code that allows the object(s) to be added to the list.

        void List::add(Polynom &polynom)
    {
        Polynom *temp = new Polynom(); // Выделяем память под новый объект 
        temp->Next = HEAD; // меняем адрес начала списка 
    
    temp->degree = polynom.degree;
    temp->coefficient = polynom.coefficient;
    cout << *temp; // покажем что записалось
    
    size++; // увеличиваем переменную хранящую размер на 1
    HEAD = temp; // меняем адрес начала списка
    

    }

    There is a function of delisting all added facilities.

    void List::show()
    {
    Polynom *temp = HEAD; // объявляем указатель и пусть он указывает на начало списка
    int i = 0;

    while (temp != NULL) // пока есть на что указывать
    {
        cout << i << " полином: ";
        cout << *temp;
        cout << endl << endl;
    
        cout << endl;
        temp = temp->Next;
        i++;
    }
    

    }

    But for some reason, if a few (n) many members are added to the main function and then asked to withdraw them, the list will remove n of the same many members equal to the latter.

    List list;

                Polynom poly;
                cout << "Введите количество вводимых многочленов >> ";
                int n;
                cin >> n;
                cout << "\nВведите степень многочленов >> ";
                cin >> degree;
                poly.setDegree(degree);
    
                for (int i = 0; i < n; i++)
                {
                    cout << "\n Введите " << i << " многочлен\n";
                    cin >> poly;
                    list.add(poly);
                    cout << endl;
                }
                list.show();
    

    Вот как это выглядит

    I take it the mistake's running around, because the entry seems right. The indicators will be downloaded and all members are not recorded in one place. Please make a mistake.

    The error was in the water of the coefficient array:
    changed. temp->coefficient = polynom.coefficient;

    That's it.

    `for (int i = 0; i <= polynom.getDegree(); i++)
    temp->coefficient[i] = polynom.coefficient[i];



  • Incorrect input error:

    change temp->coefficient = polynom.coefficient;

    That's it.

    for (int i = 0; i <= polynom.getDegree(); i++)
            temp->coefficient[i] = polynom.coefficient[i];
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2