Facebook
From Beige Partdridge, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 94
  1. int choice=0;
  2.     BST intTree;
  3.     do
  4.     {
  5.         system("cls");
  6.         cout <<"\n================MENU=================";
  7.         cout <<"\n1. Tao cay nhi phan gom n nut, moi nut luu 1 phan tu cua mang so nguyen cho truoc";
  8.         cout <<"\n2. Xuat cay theo thu tu tang dan";
  9.         cout <<"\n3. Xuat cay theo thu tu giam dan";
  10.         cout <<"\n4. Nut chua khoa X";
  11.         cout <<"\n5. Nut co gia tri lon nhat";
  12.         cout <<"\n6. Nut co gia tri nho nhat";
  13.         cout <<"\n7. Tong cac node tren cay";
  14.         cout <<"\n8. Xoa node co  gia tri la x";
  15.         cout <<"\n9. Thoat";
  16.         cout <<"\nNhap lua chon: ";
  17.         cin>>choice;
  18.         switch (choice)
  19.         {
  20.         case 1:{
  21.             int n;
  22.             cout <<"\nNhap so phan tu cua mang";
  23.             cin >>n;
  24.             int *a=new int[n];
  25.             for (int i = 0; i < n; i++)
  26.             {
  27.                 cout <<"\nx["<<i<<"]= ";
  28.                 cin>>a[i];
  29.                 intTree.insert(intTree.getRoot(),a[i]);
  30.             }
  31.             delete a;
  32.             break;
  33.         }
  34.         case 2:{
  35.             cout <<"\n----Xuat theo chieu tang dan----";
  36.             intTree.inOrderInCrease(intTree.getRoot());
  37.             break;
  38.         }
  39.         case 3:{
  40.             cout <<"\n----Xuat theo chieu giam dan----";
  41.             intTree.inOrderDecrease(intTree.getRoot());          
  42.             break;
  43.         }
  44.         case 4:{
  45.             int x;
  46.             cout <<"\nNhap gia tri x: ";
  47.             cin>>x;
  48.             intTree.search(intTree.getRoot(),x);
  49.             cout <<"\nDa tim thay node co gia tri ";
  50.             break;
  51.         }
  52.         case 5:{
  53.             Node *temp=intTree.minValue(intTree.getRoot());
  54.             cout <<"\nNode co gia tri nho nhat co gia tri la: \t"<<temp->data;
  55.             break;
  56.         }
  57.         case 6:{
  58.             Node *temp=intTree.maxValue(intTree.getRoot());
  59.             cout <<"\nNode co gia tri nho nhat co gia tri la: \t"<<temp->data;
  60.             break;
  61.         }
  62.         case 7:{
  63.             cout <<"\nTong cac gia tri cua node la: "<<intTree.sumValue(intTree.getRoot());
  64.             break;
  65.         }
  66.         case 8:{
  67.             int x;
  68.             cout <<"\nNhap gia tri can xoa";
  69.             cin>>x;
  70.             intTree.reMove(intTree.getRoot(),x);
  71.             cout <<"\nDa xoa thanh cong";
  72.         }
  73.         default:
  74.             break;
  75.         }
  76.         system("pause");
  77.     } while (choice !=9);