bai 2 (de)
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct TagSINHVIEN
{
char masinhvien[8];
char tensinhvien[20];
int namsinh;
float dtoan;
float dly;
float dhoa;
} SINHVIEN;
typedef struct TagNODE
{
SV Info;
NODE *pNext;
}NODE;
typedef struct TagLIST
{
NODE *pHead;
NODE *pTail;
}LIST;
void Init (LIST &l)
{
l.pHead=l.pTail=NULL;
}
NODE *GetNode(SINHVIEN sv)
{
NODE *p;
p=new NODE;
if (p==NULL)
{
cout<<"Khong du bo nho!";
return NULL;
}
p->Info=sv;
p->pNext=NULL;
return p;
}
void AddFirst(LIST &L, NODE* new_ele)
{
if (L.pHead == NULL)
L.pHead = L.pTail = new_ele;
else {
new_ele->pNext =L.pHead;
L.pHead = new_ele;
}
}
NODE* InsertHead(LIST &L,SINHVIEN sv)
{
NODE* new_ele = GetNode(x);
if (new_ele == NULL)
return NULL;
AddFirst(L, new_ele);
return new_ele;
}
void AddTail(LIST &L, NODE *new_ele)
{
if (L.pHead==NULL)
L.pHead=L.pTail=new_ele;
else
L.pTail=L.pTail->pNext=new_ele;
}
NODE* InsertTail(LIST &L,SINHVIEN sv)
{
NODE* new_ele=GetNode(sv);
if (new_ele==NULL)
return NULL;
AddTail(L, new_ele);
return new_ele;
}
void InputList (LIST &L)
{
cout<<"So sinh vien can nhap: ";
cin>>n;
for(int i=0;i<n;i++)
{
SINHVIEN sv;
cout<<"
Nhap ma sinh vien: ";cin>>sv.masinhvien;
cout<<"Nhap ten sinh vien: ";cin>>sv.tensinhvien;
cout<<"Nhap nam sinh: ";cin>>sv.namsinh;
cout<<"Nhap diem toan: ";cin>>sv.dtoan;
cout<<"Nhap diem ly: ";cin>>sv.dly;
cout<<"Nhap diem hoa: ";cin>>sv.dhoa;
InsertHead(L,sv);
}
}
void OutputList (LIST L)
{
NODE* p;
p=L.pHead;
while(p!=NULL)
{
cout<<"
Ma sinh vien: "<<p->Info.masinhvien;
cout<<"
Ten sinh vien: "<<p->Info.tensinhvien;
cout<<"
Nam sinh: "<<p->Info.namsinh;
cout<<"
Diem Toan: "<<p->Tnfo.dtoan;
cout<<"
Diem Ly: "<<p->Tnfo.dly;
cout<<"
Diem Hoa: "<<p->Tnfo.dhoa;
p=p->pNext;
}
}
vi du:
\*void ListSelectionSort (LIST &L)
{
NODE* min,* p,* q;
p = L.pHead;
while(p != L.pTail)
{
q = p->pNext; min = p;
while(q != NULL)
{
if(q->Info.dientich< min->Info.dientich )
min = q;
q = q->pNext;
}
Tinh Info=p->Info;
p->Info=min->Info;
min->Info=Info;
p = p->pNext;
}
}*/
/*Tu viet ham main */
int _tmain(int argc, _TCHAR* argv[])
{
clrscr();
LIST L;
Init(L);
InputList(L);
OutputList(L);
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top