Функция отображения и удаления в данном связанном списке идет в бесконечном цикле - PullRequest
0 голосов
/ 26 марта 2020

Ссылка для полного кода https://rebrand.ly/gk8vyi7

//Adding this block so that you can check if I am not making any mistake while inserting any data
void linked_list::insert_at_the_beginning() {
    node *new_node = new node;
    node *temp;
    cout<<"Enter a number";
    cin>>new_node->data;
    cout<<"Successfully Inserted"<<endl;
    if(START == nullptr) {
        START = new_node;
        END = new_node;
    }
    new_node->next = START;
    START = new_node;
    //To see if address of node START is changing or not after adding in beginning of linked list
    cout<<START<<endl;
    temp = START;
}



int linked_list::delete_from_the_end() {
    int data;
    node *temp, *t;
    temp = START;
    //taking address of START in temp 
    while(temp != nullptr) {
        t = temp;
        //going to next element
        temp = temp->next;
    }
    data = temp->data;
    delete temp;
    t->next = nullptr;

    return data;
}

void linked_list::display(){
    node* temp;
    temp = START;
    //Taking address of START in temp
    while (temp!=nullptr)
    {
        cout<<temp->data<<endl;
        temp = temp->next;
    }

}

Для ввода: 1 2 3 4 5 Функция отображения и удаления имеет бесконечное значение l oop, кроме того 1-й элемент, отображающий должно быть 5, как я вставляю в начале, но это печать 1 бесконечно

...