c++ Как в новом списке чтобы не печатало количество введенных элементов и в новом списке отображалась дробная часть
У меня программа работает правильно, но при выводе нового списка выходит в печать и введенное количество элементов и в новом списке не удаляет одинаковые вещественные числа и не отображается дробная часть, только целая. Что отображается есть на фото: как это убрать "6" и чтобы выходило не "2" два раза, а один раз "2,12". Подскажите, пожалуйста.
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <Windows.h>
using namespace std;
struct node // узел
{
int inf;
node* next;
};
struct list // список
{
node* head = nullptr;
list(int n)
{
head = new node;
head->inf = n;
head->next = nullptr;
}
void clear() // очистка
{
node* ptr1 = head, * ptr2 = head->next;
while (ptr2)
{
ptr1 = ptr2;
ptr2 = ptr2->next;
delete ptr1;
}
delete head;
head = nullptr;
}
~list()
{
(*this).clear();
}
void add(int n) // добавление
{
node* ptr = head;
if (ptr)
{
while (ptr->next)
ptr = ptr->next;
ptr->next = new node;
ptr->next->inf = n;
ptr->next->next = nullptr;
}
else
{
head = new node;
head->inf = n;
head->next = nullptr;
}
}
void print() // печать
{
node* ptr = head;
if (ptr)
{
while (ptr)
{
cout << ptr->inf << ' ';
ptr = ptr->next;
}
cout << '\n';
}
else cout << "Нет элементов\n";
}
void remove_duplicates() // удаление повторяющихся элементов
{
node* current = head;
node* next_next;
if (current == NULL)
return;
while (current->next != NULL)
{
if (current->inf == current->next->inf)
{
next_next = current->next->next;
delete(current->next);
current->next = next_next;
}
else
{
current = current->next;
}
}
}
};
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n;
printf("\nВведите количество элементов: ");
cin >> n;
list lst(n);
for (int i = 0; i < n; i++)
{
float element;
cout << "Введите элемент " << i + 1 << ": ";
cin >> element;
lst.add(element);
}
lst.print();
lst.remove_duplicates();
printf("\nНовый список: ");
lst.print();
system("pause");
return 0;
}
Источник: Stack Overflow на русском