em chạy thì báo lỗi phần hàm addhead mông anh chị giải quyết giùm
PHP Code:
// danh sach sinh vien.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
typedef struct sinhvien
{
char hoten[30];
int mssv;
float diem;
}sv;
typedef struct tagnode
{
sv data;
struct tagnode *next;
struct tagnode *prew;
}node;
typedef struct taglist
{
node *head;
node *tail;
}list;
void creatlist(list &l)
{
l.head = l.tail = NULL;
}
node* creatnode(sv x)
{
node *p;
p = new node;
p->data = x;
p->next = p->prew = NULL;
return p;
}
void addhead(list &l,sv x)
{
node *p;
p=creatnode(x);
if(l.head == NULL)
l.head = l.tail = p;
else
{
p->next = l.head;
l.head -> prew = p;
l.head = p;
}
}
void addtail(list &l,node *p)
{
if(l.head == NULL)
l.head = l.tail = NULL;
else
{
l.tail->next = p;
p ->prew = l.tail;
l.tail = p;
}
}
void inputsinhvien(list &l)
{
sv x;
printf("moi ban nhap danh sach sinh vien den khi nhap ten rong:\n");
do
{
fflush(stdin);
printf("\nho va ten:"); gets(x.hoten);
if(x.hoten[0]==0)
break;
printf("\nmssv: "); scanf("%d",&x.mssv);
printf("\ndiem: "); scanf("%d",&x.diem);
addhead(l,x);
}while(x.hoten[0]!=0);
}
void outsinhvien(list l)
{
if(l.head == NULL)
printf("danh sach rong!");
else
{
node *p=l.head;
while(p != NULL)
{
printf("%-30s%-5d%-4.2f\n",p->data.hoten,p->data.mssv,p->data.diem);
p = p->next;
}
}
}
void main()
{
list l;
creatlist(l);
inputsinhvien(l);
outsinhvien(l);
getch();
}
Comment