mn có thề xem giúp chương trình này với nó cứ bị lỗ hàm hói thôi ak
#include <iostream>
#include <string>
#include <iomanip>
#include <malloc.h>
using namespace std;
#define TRUE 1;
#define FALSE 0;
typedef struct sinhvien
{
int mssv;
char hoten[12];
float dtb;
}sinhvien;
// cau truc mot nut trong danh sach lien ket don
typedef struct node
{
sinhvien info;
struct node*next;
};
//khai bao kieu con tro chi den nut
typedef node *NODEPTR;
void initialize(NODEPTR*plist)//khoi tao danh sach lien ket
{
*plist=NULL;
}
NODEPTR getnode(void)//cap phat bo nho cho 1node
{
NODEPTR P;
P=(NODEPTR) malloc(sizeof(struct node));
return(P);
}
void Freenode(NODEPTR P)//xoa 1nut
{
free(P);
}
int empty(NODEPTR*plist)// kiem tra ds co rong ko
{
return (*plist==NULL? 1:0);
{
void traverse(NODEPTR *plist)//duyet ds
{
NODEPTR p;
int stt=0;
p=*plist; //cho p tro nut dau
if(empty(plist))
{
cout<<"danh sach rong"<<endl;
}
else
{
//di chuyen p di qua tung nut trong danh sach
while(p!=NULL)
{
cout<<endl<<stt++<<setw(15)<<p->info.mssv<<setw(16)<<p->info.hoten<<setw(10)<<p->info.dtb;
p=p->next;
}
}
void push (NODEPTR *plist,sinhvien x)//them mot node vao ds
{
NODEPTR p;
p= getnode();
p ->info=x;
p ->next=*plist;
*plist=p;
}
sinhvien pop(NODEPTR *plist)
{
NODEPTR p;
sinhvien x;
p=*plist;
*plist=p ->next;
x=p ->info;
freenode(p);
}
int main()
{
NODEPTR plist;
NODEPTR P;
sinhvien x;
int chon=1;
initialize(&plist);
while(chon!=0)
{
cout<<" \n thu muc chinh "<<endl;
cout<<" 1- xem danh sinh vien "<<endl;
cout<<" 2- Them sinh vien vao danh sach"<<endl;
cout<<" 3- xoa sinh vien "<<endl;
cout<<" 4- hieu chinh sinh vien "<<endl;
cout<<" 5- sp xep sinh vien theo MSSV"<<endl;
cout<<" 6- tim kiem sinh vien theo MSSV"<<endl;
cout<<" 7- them sinh vien vao danh sach theo ma so sinh vien"<<endl;
cout<<"0. thoat"<<endl;
cout<<"bam chon "<<endl;
cin>>chon ;
if (chon==1)
{
cout<<" danh sach sinh vien "<<endl;
cout<<" \nSTT MSSV HOVATEN DIEM TB "<<endl;
traverse(&plist);
}
if(chon==2)
{
cout<<"\nnhap mssv: ";
cin>>(x.mssv);
cin.ignore();
cout<<"\nnhap ho ten ";
cin.getline(x.hoten,12);
cout<<"\nnhap diem so ";
cin>>x.dtb;
push(&plist, x);
}
if(chon==3);
if(chon==4);
if(chon==6);
if(chon==7);
} }