Chatbox

Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
16/12/2012 16:12 # 1
d4rkknight
Cấp độ: 1 - Kỹ năng: 1

Kinh nghiệm: 4/10 (40%)
Kĩ năng: 4/10 (40%)
Ngày gia nhập: 03/04/2011
Bài gởi: 4
Được cảm ơn: 4
Giúp làm bài toàn sinh viên trên cây nhị phân tìm kiếm


 

//Xem giúp em hàm tìm kiếm sinh viên 
//và hàm xóa sinh viên với 

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
struct SinhVien
{
char Hoten[30];
char xeploai[10];
int toan;
int ly;
int hoa;
int dtb;
};
struct  Node
{
  SinhVien SV;
  Node *pL,*pR;
};
typedef  Node*TREE;
 
void KHOITAO(TREE &T)
{
     T=NULL;
}
TREE TaoNode(SinhVien TTSV,TREE L ,TREE R)
{
   TREE e;
   e=new Node;
   strcpy(e->SV.Hoten,TTSV.Hoten);
   e->SV.toan=TTSV.toan;
   e->SV.ly=TTSV.ly;
   e->SV.hoa=TTSV.hoa;
   e->SV.dtb=TTSV.dtb;
   strcpy(e->SV.xeploai,TTSV.xeploai);
   e->pL=L;
   e->pR=R;
   return  e;
}
void NHAPSV(SinhVien  &k)
{
 
printf("\n Nhap ten sinh vien :");
scanf("%s",&k.Hoten);
 
printf("\n DiemToan :");
scanf("%d",&k.toan);
printf("\n Diem ly :");
scanf("%d",&k.ly);
printf("\n Diem Hoa:");
scanf("%d",&k.hoa);
 
k.dtb=(k.toan+k.ly+k.hoa)/3;
if (k.dtb>=8)
 strcpy(k.xeploai,"GIOI");
else
 
 if(k.dtb>=6)
 
   strcpy(k.xeploai,"KHA");
 
 else
 
  if(k.dtb>=5)
 
     strcpy(k.xeploai,"TB");
 
  else
 
   strcpy(k.xeploai,"YEU");
 
}
 
 
 
void DUYET(TREE T)
{
if (T!=NULL)
{
cout<<"\n";
puts(T->SV.Hoten);
cout<<"\t"<<T->SV.toan;
cout<<"\t"<<T->SV.ly;
cout<<"\t"<<T->SV.hoa;
cout<<"\t"<<T->SV.dtb;
cout<<"\t"<<T->SV.xeploai;
DUYET(T->pL);
DUYET(T->pR);
}
}
void ChenCay(TREE &T,TREE k)
{
 if (T!=NULL)
 {
   if (strcmp(T->SV.Hoten,k->SV.Hoten)==0) cout <<"\nDa co sinh vien nay";
   else
     if ((strcmp(T->SV.Hoten,k->SV.Hoten) >0))  ChenCay(T->pL,k);
     else  ChenCay(T->pR,k);
  }
else
{
  T=k;
}
}
 
/*//TH2: Cây da co phan tu
TREE timkiem(TREE T,TREE x){
    if (T->pL==NULL&&x->SV.Hoten<T->SV.Hoten){
T->pL=x;
return x;
    }
    if (T->pR==NULL&&x->SV.Hoten>T->SV.Hoten){
T->pR=x;
return x;
    }
    if (T->pL&&x->SV.Hoten<T->SV.Hoten)timkiem(T->pL,x);
    if (T->pR&&x->SV.Hoten>T->SV.Hoten)timkiem(T->pR,x);*/
TREE timkiem(TREE T,int K)
{
    if (T==NULL) return NULL;
    if (T->SV.Hoten==K) return T;
    if (K<T->SV.Hoten) return timkiem(T->pL,K);
    if (K>T->SV.Hoten) return timkiem(T->pR,K);
}
void Delete(TREE T){
    if (T==NULL) return;
    int K;
    cout<<"\n Nhap ten sinh vien can xoa X= ";
    cin>>K;
    TREE S=timkiem(T,K);
    if (S==NULL){
        cout<<"Khong tim thay "<<K<<endl;
        return;
    }
    Delete_SV(T,S);
void  main()
{
   int n;
   SinhVien s;
   TREE T,e;
   clrscr();
  cout << "\n\n\t \t \t 1.KHOI TAO";
cout << "\n\n\t \t \t 2.NHAP TTSV";
cout << "\n\n\t \t \t 3.DUYET";
cout << "\n\n\t \t \t 4.CHEN SINH VIEN VAO CAY";
cout << "\n\n\t \t \t 5.HIEN THI TTSV";
cout << "\n\n\t \t \t 6.KET THUC";
 
   KHOITAO(T);
   cout<<"\nNhap so sinh vien : ";cin>>n;
   for(int i=1;i<=n;i++)
   {
      NHAPSV(s);
      e=TaoNode(s,NULL,NULL);
      ChenCay(T,e);
 
 
   }
   DUYET(T);
   cout<<" \n Nhap thong tin cua sinh vien can chen:";
   NHAPSV(s);
   e=TaoNode(s,NULL,NULL);
   ChenCay(T,e);
   cout<<"\n Danh sach sau khi chen them mot sinh vien la:";
   DUYET(T);
   timkiem(T,K);
   T=timkiem(T,K);
   cout<<"\n nhap thong tin sinh vien can tim la:";cin>>K;
   getch();
}

 




 
Copyright© Đại học Duy Tân 2010 - 2024