Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<stdio.h>
- #include<string.h>
- using namespace std;
- struct SinhVien
- {
- int n;
- char MaSV[10];
- char TenSV[10];
- int NamSinh;
- float Diem;
- };
- void NhapDSSV(SinhVien ds[], int &n)
- {
- cout<<"NHap Vao So Sinh Vien n:";
- cin>>n;
- for (int i=0;i<n;i++)
- {
- cout<<"\n\tNHap Thong Tin Sinh Vien Thu:"<<i+1;
- cout<<"\n\t\t Nhap Ma Sinh Vien:";
- flushall();
- gets(ds[i].MaSV);
- cout<<"\n\t\t Nhap Ten Sinh Vien :";
- flushall();
- gets(ds[i].TenSV);
- cout<<"\n\t\t Nhap Nam Sinh Cua Sinh Vien:";
- cin>>ds[i].NamSinh;
- cout<<"\n\t\t NHap Diem Cua Sinh Vien:";
- cin>>ds[i].Diem;
- }
- }
- void XuatDSSV(SinhVien ds[], int n)
- {
- cout<<"Thong Tin Sinh Vien Co Trong Danh Sach La :\n";
- cout<<"\nMa SV"<<"\t"<<"Ten SV"<<"\t"<<"Nam Sinh"<<"\t"<<"DiemTB"<<endl;
- cout<<"=======================================================\n";
- for(int i=0;i<n;i++)
- cout<<ds[i].MaSV<<"\t"<<ds[i].TenSV<<"\t"<<ds[i].NamSinh<<"\t"<<ds[i].Diem<<endl;
- }
- void InterchangeSortTang (SinhVien ds[], int n)
- {
- for(int i=0;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(ds[i].Diem > ds[j].Diem)
- swap(ds[i].Diem,ds[j].Diem);
- }
- void QuickSortTang(SinhVien ds[], int l , int r)
- {
- int m=(l+r)/2; int x=ds[m].Diem;
- int i=l;
- int j=r;
- do
- {
- while (ds[i].Diem<x)
- i++;
- while(ds[j].Diem>x)
- j--;
- {
- swap(ds[i].Diem,ds[j].Diem);
- i++;
- j--;
- }
- }
- while (i<j);
- if(l<j)
- QuickSortTang(ds,l,j);
- if(i<r)
- QuickSortTang(ds,i,r);
- }
- void main()
- {
- SinhVien ds[50];
- int n,x;
- NhapDSSV(ds,n);
- XuatDSSV(ds,n);
- InterchangeSortTang(ds,n);
- cout<<"\n DS Sinh Vien Co Diem Tang Dan Theo Interchangesort:";
- XuatDSSV(ds,n);
- QuickSortTang(ds,l,r);
- cout<<" Cac SV Diem Tang Dan Theo QuickSort :";
- XuatDSSV(ds,n);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement