#include"List.h"
LIST::LIST()
{
head = new Node();
head->next = nullptr;
before = head;
}
void LIST::Insert()
{
std::cout << "추가할 정보를 기입해주세요." << std::endl;
std::cout << "회원의 이름을 기입하세요: ";
std::cin >> Name;
std::cout << "연락처를 기입하세요: ";
std::cin >> num;
std::cout << "주소를 기입하세요: ";
std::cin >> Address;
for (Node *ptr = head; ptr->next != nullptr; ptr = ptr->next)
{
if ((ptr->Get_name() == Name) && (ptr->Get_number() == num) && (ptr->Get_address() == Address))
{
std::cout << "중복되는 정보가 있습니다." << std::endl;
return;
}
}
Node* newNode = new Node();
newNode->Set_name(Name);
newNode->Set_number(num);
newNode->Set_address(Address);
newNode->next = head->next;
head->next = newNode;
}
void LIST::Delete()
{
std::cout << "삭제할 정보를 정확히 기입해주세요." << std::endl;
std::cout << "회원의 이름을 기입하세요: ";
std::cin >> Name;
std::cout << "연락처를 기입하세요: ";
std::cin >> num;
std::cout << "주소를 기입하세요: ";
std::cin >> Address;
for (Node *ptr = head; ptr != nullptr; ptr = ptr->next)
{
Node *remove = ptr;
if ((ptr->Get_name() == Name) && (ptr->Get_number() == num) && (ptr->Get_address() == Address))
{
before->next = ptr->next;
ptr = before;
delete remove;
return;
}
before = ptr;
}
std::cout << "그러한 정보가 없습니다." << std::endl;
}
void LIST::print()
{
std::cout << "--------------------------------------------" << std::endl;
std::cout << "회원의 이름" << std::endl;
std::cout << "연락처" << std::endl;
std::cout << "주소지" << std::endl;
std::cout << "--------------------------------------------" << std::endl;
for (Node *ptr = head->next; ptr != nullptr; ptr = ptr->next)
{
std::cout << ptr->Get_name() << std::endl;
std::cout << ptr->Get_number() << std::endl;
std::cout << ptr->Get_address() << std::endl;
}
std::cout << "--------------------------------------------" << std::endl;
}