Code Danh sách móc nối đơn

22:21 0 Comments


/*DANH SACH MOC NOI DON QUAN LY SINH VIEN*/
#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct SINHVIEN{
char masv[10];
char hoten[20];
float dtb;
};

struct Node{
SINHVIEN infor;
Node *next;
} *L;

void nhap(Node *&L)
{
Node *q; char s[10];
L=new Node;
q=L;
cout<<"Nhap vao ma sinh vien : "; fflush(stdin); gets(L->infor.masv);
cout<<"Nhap ho ten sinh vien :"; fflush(stdin); gets(L->infor.hoten);
cout<<"diem trung binh : "; cin>>L->infor.dtb;
cout<<"Nhap vao ma sinh vien :"; fflush(stdin); gets(s);
while(strcmp(s,""))
{
q->next=new Node;
q=q->next;
strcpy(q->infor.masv,s);
cout<<"Nhap ho ten sinh vien :"; fflush(stdin); gets(q->infor.hoten);
cout<<"diem trung binh : "; cin>>q->infor.dtb;
cout<<"Nhap vao ma sinh vien :"; fflush(stdin); gets(s);
}
q->next=NULL;
}

void nhap2(Node *&L)
{
Node *q;char s[10];
L=new Node;
q=L;
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(L->infor.masv);
cout<<"Nhap ho ten sinh vien : ";fflush(stdin); gets(L->infor.hoten);
cout<<"diem trung binh : "; cin>>L->infor.dtb;
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(s);
while(strcmp(s,""))
{
Node *p=L;
while(p!=p&&strcmp(s,p->infor.masv))
p=p->next;
if(strcmp(p->infor.masv,s)) {
q->next=new Node;
q=q->next;
strcpy(q->infor.masv,s);
cout<<"Nhap ho ten sinh vien : "; fflush(stdin); gets(q->infor.hoten);
cout<<"dien trung binh : "; cin>>q->infor.dtb;
}
else
cout<<"\tMa Trung Roi Kia nhap lai di !!! \n ";
cout<<"Nhap ma sinh vien : ";
fflush(stdin); gets(s);
}
q->next=NULL;
}

void hien(Node *L)
{
if(L!=NULL)
{
cout<<"========== DANH SACH SINH VIEN ==========\n";
while(L!=NULL)
{
cout<<setw(10)<<L->infor.masv<<setw(10)<<L->infor.hoten<<setw(10)<<L->infor.dtb<<endl;
L=L->next;
}
}
else cout<<"Danh Sach trong roi\n";
}

void sapgiam(Node *L)
{
Node *q,*p;SINHVIEN tg;
if(L!=NULL)
{
q=L;
while(q->next!=NULL)
{
p=q->next;
while(p!=NULL)
{
if(p->infor.dtb > q->infor.dtb)
{
tg=p->infor;
p->infor=q->infor
;q->infor=tg;
}
p=p->next;
}
q=q->next;
}
}
}


void saptang(Node *L)
{
Node *q,*p;SINHVIEN tg;
if(L!=NULL)
{
q=L;
while(q->next!=NULL)
{
p=q->next;
while(p!=NULL)
{
if(p->infor.dtb < q->infor.dtb)
{
tg=q->infor;
q->infor=p->infor;
p->infor=tg;
}
p=p->next;
}
q=q->next;
}
}
}

void loaidau(Node *&L)
{
Node *q;
q=L;
L=L->next;
delete q;
}
void loaicuoi(Node *&L)
{
Node *q;
if(L!=NULL)
{
if(L->next==NULL)
{
L=NULL;
delete L;
}
else{
q=L;
while(q->next->next!=NULL)
q=q->next;
Node *p;
p=q->next;
q->next=NULL;
delete p;
}
}
}

void loaitang(Node *&L)
{
Node *q;
if(L!=NULL){
while(L!=NULL&&L->infor.dtb<5)
{
q=L;
L=L->next;
delete q;
}
}
}

void loaigiam(Node *&L)
{
Node *q,*p;
if(L->infor.dtb<5){
L=NULL;
delete L;
}
if(L!=NULL){
p=L;
while(p->next!=NULL&&p->next->infor.dtb>=5)
p=p->next;
q=p->next;
p->next=NULL;
delete q;

}
}

void loai(Node *&L)
{
Node *q=L,*p;
if(L!=NULL){
while(q->next!=NULL)
{
if(q->next->infor.dtb<5)
{
p= q->next;
q->next=p->next;
delete p;
}
else
q=q->next;
}
if(L->infor.dtb<5){
p=L;
L=L->next;
delete p;
}
}
}

void chendau(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen :\n";
cout<<"Mã sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"Diem trung binh : "; cin>>x->infor.dtb;
x->next=L;
L=x;
}

void chencuoi(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao sinh vien can chen :\n";
cout<<"Nhap ma sv : "; fflush(stdin); gets(x->infor.masv);
cout<<"Ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"Diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL){
Node *q=L;
while(q->next!=NULL)
q=q->next;
q->next=x;
}
else L=x;

}

void chensxt(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen : ";
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Nhap vao ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL)
{
if(L->infor.dtb > x->infor.dtb)
{
x->next=L;
L=x;
}
else{
Node *p=L;
while(p->next!=NULL&&x->infor.dtb < p->next->infor.dtb)
{
x->next=p->next;
p->next=x;
}
}
}
else L=x;
}

void chensxg(Node *&L)
{
Node *x;
x=new Node;
cout<<"Nhap vao thong tin sinh vien can chen : ";
cout<<"Nhap ma sinh vien : "; fflush(stdin); gets(x->infor.masv);
cout<<"Nhap vao ho ten sinh vien : "; fflush(stdin); gets(x->infor.hoten);
cout<<"diem trung binh : "; cin>>x->infor.dtb;
if(L!=NULL)
{
if(L->infor.dtb > x->infor.dtb)
{
x->next=L;
L=x;
}
else{
Node *p=L;
while(p->next!=NULL&&x->infor.dtb < p->next->infor.dtb)
{
x->next=p->next;
p->next=x;
}
}
}
else L=x;
}

void daochieu(Node *&L)
{
if(L!=NULL)
{
Node *p,*q;
q=NULL;p=L;
while(L->next!=NULL){
L=L->next;
p->next=q;
q=p;
p=L;
}
L->next=q;
}
}

void trungma(Node *&L)
{
if(L!=NULL)
{
Node *q,*p,*k;

p=L;
while(p->next!=NULL)
{
q=p;
while(q->next!=NULL)
{
if(strcmp(q->next->infor.masv,p->infor.masv)==0)
{
k=q->next;
q->next=k->next;
delete k;
}
else q=q->next;
}
if(p->next!=NULL) p=p->next;
}
}
}

int main()
{
nhap(L);
//nhap2(L);
hien(L);
//saptang(L);
//loaitang(L);
//chensxt(L);
//sapgiam(L);
//loaigiam(L);
//loai(L);
//loaidau(L);
//loaicuoi(L);
//chendau(L);
//chencuoi(L);
//daochieu(L);
trungma(L);
hien(L);
return 0;
}

0 nhận xét: