Не выводится список, думаю проблема в добавлении, в цикле while
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
class List
{
private:
Node *head;
public:
List()
{
head = NULL;
}
void push_list(int a)
{
Node *uzel = new Node;
uzel->data = a;
uzel->next = NULL;
if (head == NULL)
{
head = uzel;
}
else
{
Node *current = head;
while (current->next!=NULL)
{
current = current->next;
current->next = uzel;
}
}
}
void print()
{
Node *current = head;
while (current!= NULL)
{
cout << current->data << endl;
current = current->next;
}
}
};
int main()
{
List name;
name.push_list(6);
name.push_list(7);
name.push_list(8);
name.print();
return 0;
}
Ответы (1 шт):
Автор решения: KoVadim
→ Ссылка
Вам нужно одну строку переставить в push_back
Было
while (current->next!=NULL)
{
current = current->next;
current->next = uzel;
}
Стало
while (current->next!=NULL)
{
current = current->next;
}
current->next = uzel;