30/09/2018, 18:46
Lỗi hàm in thông tin trong code C++ - Môn cấu trúc dữ liệu và giải thuật

sau khi nhập thông tin xong em xem lại thông tin đã nhập thì bị lỗi như này, mấy chế xem hộ em với.
#include<iostream>
#include<conio.h>
using namespace std;
struct sinhvien{
char ten[50];
long ma;
};
struct node{
sinhvien info;
node *next;
};
struct danhsach{
node *pdau;
node *pcuoi;
};
void khoitao(danhsach &d){
d.pdau=d.pcuoi=NULL;
}
int ktrong(danhsach d){
return d.pdau==NULL;
}
//int ktday(danhsach d){
// return d.pcuoi==FULL;
//}
void themcuoi(danhsach &d, sinhvien sv){
node *p = new node;
p->next=NULL;
p->info=sv;
if(ktrong(d)){
d.pdau=d.pdau=p;return;
}
d.pcuoi->next=p;
d.pcuoi=p;
}
void xem(danhsach d){
if(ktrong(d))return;
node *p=d.pdau;
while(p!=NULL){
cout<<"
"<<p->info.ma<<"
"<<p->info.ten;
p=p->next;
}
}
void nhapsv(sinhvien sv){
cout<<"
Nhap vao ma sinh vien:";
cin>>sv.ma;
cout<<"
Nhap vao ten sinh vien:";
fflush(stdin);
cin.getline(sv.ten,sizeof (sv.ten),'
');
}
int main(){
danhsach dssv;
sinhvien sv;
int a=1,chon;
khoitao(dssv);
while(a){
cout<<endl<<"1.Them sinh vien:";
cout<<endl<<"2.Xem danh sach:";
cout<<endl<<"3.Xoa danh sach:";
cout<<endl<<"4.Thoat chuong trinh.";
cout<<endl<<"Chon thao tac.";
cin>>chon;
switch(chon){
case 0: a=0;break;
case 1: nhapsv(sv);
themcuoi(dssv,sv);break;
case 2: xem(dssv);break;
case 3: break;
}
}
return 0;
}
còn nữa, em tạo thêm thông tin vào thì chương trình bị dừng luôn.

Bài liên quan