#include<iostream>
using namespace std;
struct ngay
{
int ngay;
int thang;
int nam;
};
struct nhanvien
{
char ten[30];
ngay ngaysinh;
float luong;
int gioitinh;
};
struct node
{
nhanvien info;
struct node*pNext;
};
struct list
{
node*pHead;
node*pTail;
};
node*getnode(nhanvien x)
{
node*p = new node;
if (p == NULL)
return NULL;
p->info = x;
p->pNext = NULL;
return p;
}
void init(list &l)
{
l.pHead = NULL;
l.pTail = NULL;
}
void nhap(nhanvien &a)
{
cout << "hoten: ";
cin >> a.ten;
cout << "ngaysinh: ";
cin >> a.ngaysinh.ngay >> a.ngaysinh.thang >> a.ngaysinh.nam;
cout << "luong: ";
cin >> a.luong;
cout << "gioi tinh: ";
cin >> a.gioitinh;
}
void nhaplist(list &l)
{
int n;
cout << "nhap so luong";
cin >> n;
init(l);
for (int i = 1; i <= n; i++)
{
nhanvien x;
nhap(x);
node*p=getnode(x);
if (p == NULL)
addhead(l,p);
}
}
void addhead(list &l, node*p)
{
if (l.pHead == NULL)
l.pHead = l.pTail = p;
else
{
p->pNext = l.pHead;
l.pHead = p;
}
}
int main()
{
list l;
init(l);
nhaplist(l);
return 0;
}
Mình code nhưng bị lỗi: "CL.exe" exited with code 2 với lỗi 'addhead' identifier not found.
Ai giúp mình với, thank nhiều.
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?