어떤 분이 어제 이걸로 엄청 고생하시길래 알려드렸다.
혹시나 다른 사람들도 이걸로 고생하는사람있으면 이거 참고하면서 하길 바래
#include<iostream>
#include<string>
using namespace std;
typedef struct node
{
string name;
int id;
float salary;
node* next_node;
}NODE, * PNODE;
/**
@brief :
노드를 추가해 주는 함수
@details :
VOID
@arg :
IN NODE& header : 노드를 더 추가할 노드헤더를 넣는다.
IN const char* name : 이름
IN const int& id :아이디
IN const float& salary : salary
@return :
VOID
*/
void Add_Node(NODE& header, const char* name, const int& id, const float& salary)
{
//////////////중요한 부분////////////////////////
//////////////중요한 부분////////////////////////
//////////////중요한 부분////////////////////////
PNODE old_node = header.next_node;
//노드 추가
PNODE new_node = new NODE;
//새로 만든 노드의 전 노드로 초기화
new_node->next_node = old_node;
//header의 next_node를 new_node로 설정
header.next_node = new_node;
/////////////////////////////////////////////////
//데이터 입력
new_node->name = name;
new_node->id = id;
new_node->salary = salary;
}
/**
* @brief :
* 연결된 모든 노드의 데이터를 출력한다.
*
* @arg :
* VOID
*
* @return :
* VOID
* @
*/
void Print_Node(const NODE* header)
{
while (header->next_node)//header->next_node 가 null을 만날때까지 반복하겠다는 뜻
{
header = header->next_node; //출력할 노드 이동
//데이터 출력
cout << "이름 : " << header->name << endl
<< "아이디 : " << header->id << endl
<< "돈 : " << header->salary << endl << endl;
}
}
int main()
{
NODE header;
header.next_node = nullptr;
Add_Node(header,"human",3,3);
Add_Node(header, "huma2", 4, 4);
Print_Node(&header);
}