コード例 #1
0
ファイル: avl.cpp プロジェクト: richard-liang/leetcode
int main() {
    AVL avl;
    avl.insert(5);
    avl.print();
    avl.insert(3);
    avl.print();
}
コード例 #2
0
ファイル: tree_test.cpp プロジェクト: jmblanchard/csci333-avl
int main() {
  AVL<int>* avl = new AVL<int>();

  avl->insert(4);   // 4

  avl->insert(7);   //     4
                    //        7
  
  avl->insert(6);   //     6
                    //   4   7

  avl->insert(10);  //     6
                    //   4   7
                    //         10

  avl->insert(12);  //     6
                    //   4      10
                    //        7     12

  avl->print();

  std::cout << "\n";
  avl->remove(6);

  avl->print();
  std::cout << "\n";
  avl->printInOrder();
  std::cout << "\n";
  avl->printPostOrder();

  return 0;

}
コード例 #3
0
ファイル: avl_test.cpp プロジェクト: GregGay/csci333-avl
int main() {
  AVL<int>* avl = new AVL<int>();
  //AVL<double>* avlD = new AVL<double>();
  //AVL<std::string>* avlS = new AVL<std::string>();
  
  cout << "Pre Order Traversal Print" << endl;
  cout << endl;
  avl->insert(4);
  avl->insert(2);
  avl->insert(3);
  avl->insert(7);
  avl->insert(1);
  avl->insert(17);
  avl->insert(16);
  avl->insert(5);
  avl->print();
  cout << endl;
/*
  cout << "Post Order Traversal" << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  cout << "In Order Traversal" << endl;
  avl->inOrderTraversal();
  cout << endl;
  cout << "End!" << endl;*/
}
コード例 #4
0
ファイル: avl.cpp プロジェクト: bpan2/dsa555-w15
int main(void){
	AVL tree;
	tree.insert(10);
	tree.insert(20);
	tree.print();
	tree.insert(30);
	cout << "*********************" << endl;
	tree.print();
	for(int i=40;i< 70;i+=10){
		tree.insert(i);
		cout << "*********************" << endl;
		tree.print();
	}
//	tree.depthFirstPrint();

}
コード例 #5
0
ファイル: AVL平衡树.cpp プロジェクト: eecrazy/acmcode
int main()
{
    int n,x;
    AVL <int> avl;
    cout<<"input the number of elements:";
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>x,avl.insert(x);
    avl.print();
    return 0;
}
コード例 #6
0
ファイル: AVL.cpp プロジェクト: shanu333/Practice-Codes
int main()
{
    AVL b;
    int n, k;
    cin >> n;
    for (int i = 0; i < n; i++) {
       cin >> k;
       b.insert(k, &b.root);
    }
    b.print(b.root);
   // cout << endl << b.search(2, b.root) << endl;
    cout << "enter number of queries for del" << endl;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cout << "enter what to del\n";
        cin >> k;
        b.delete_it(k, &b.root);
        cout << endl;
        b.print(b.root);
    }

    return 0;
}
コード例 #7
0
//I used a .txt filled with employees names and ID numbers to create the AVL binary tree.
int main() 
{
    std::string file_name = "data/employees.txt";
    std::ifstream in_file(file_name);
    
    AVL <std::string, std::string> EmployeeData;
    
    //Parse the employee names and idss out of the text file
    std::string line;
    while(std::getline(in_file,line)) 
    {
        // Gets the employees name
        std::string employee_name = line.substr(0,line.find(","));
        // Gets the employees id number
        std::string employee_id = line.substr(line.find(",")+1);
        EmployeeData.insert(employee_name, employee_id);
    }
    //EmployeeData.Delete(EmployeeData.root, "Zyon Newman");
    EmployeeData.print(EmployeeData.root);
    std::cout << "Testing Lookup" << std::endl;
    std::cout << "Zyler Whitney: " << EmployeeData.lookup(EmployeeData.root, "Zyler Whitney") << std::endl;

    return 0;
}
コード例 #8
0
ファイル: avl_test.cpp プロジェクト: skavanaugh/AVLtree
int main() {
   
  int SIZE=20;
  vector<int> v(SIZE);  
  AVL<int>* avl = new AVL<int>();
  srand(time(0));  

  for (int i=0;i<SIZE;i++) {
    v[i] = 5*i;
  }
  random_shuffle(v.begin(),v.end());

  cout << "Multiples of 5 from 0 to 95 have been shuffled." << endl;
  cout << "They will be inserted into an AVL tree in the following order:" << endl << endl;  
  for (int i=0;i<SIZE;i++) {
    cout << v[i] << endl;
  }
  cout << endl;

  for (int i=0;i<SIZE;i++) {
    avl->insert(v[i]);
    cout << "After Inserting " << v[i] << endl << endl;
    avl->print();
  }
  cout << "In Order Traversal: " << endl;
  avl->inOrderTraversal();
  cout << endl << "Post Order Traversal: " << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  cout << "Now the shuffled numbers will be removed from the AVL tree ";
  cout << "in the order they were inserted." << endl << endl;
  for (int i=0;i<SIZE;i++) {
    avl->remove(v[i]);
    cout << "After Removing " << v[i] << endl << endl;
    avl->print();
  }
  
  avl->removeTree(); 
  srand(time(0)); 

  cout << "Now 20 random numbers between 0 and 99 will be inserted into an AVL tree in this order.";
  cout << endl;
  for (int i=0;i<SIZE;i++) {
    v[i] = rand() % 100;
    cout << v[i] << endl;
  }
  cout << endl;
  
  for (int i=0;i<SIZE;i++) {
    avl->insert(v[i]);
    cout << "After Inserting " << v[i] << endl << endl;
    avl->print();
  }

  cout << "In Order Traversal: " << endl;
  avl->inOrderTraversal();
  cout << endl << "Post Order Traversal: " << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  for (int i=0;i<SIZE;i++) {
    avl->remove(v[i]);
    cout << "After Removing " << v[i] << endl << endl;
    avl->print();
  }

  avl->removeTree();

  cout << "Now the numbers from 1 to 20 will be inserted into an AVL tree in order." << endl;
  cout << "They will be removed in the same order." << endl;
  for (int i=0;i<SIZE;i++) {
    v[i] = i+1;
    cout << v[i] << endl;
  }
  cout << endl;

  for (int i=0;i<SIZE;i++) {
    avl->insert(v[i]);
    cout << "After Inserting " << v[i] << endl << endl;
    avl->print();
  }

  cout << "In Order Traversal: " << endl;
  avl->inOrderTraversal();
  cout << endl << "Post Order Traversal: " << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  for (int i=0;i<SIZE;i++) {
    avl->remove(v[i]);
    cout << "After Removing " << v[i] << endl << endl;
    avl->print();
  }

  avl->removeTree();

  cout << "Now the numbers from 1 to 20 will be inserted into an AVL tree in order." << endl;
  cout << "They will be removed in REVERSE order." << endl;
  for (int i=0;i<SIZE;i++) {
    v[i] = i+1;
    cout << v[i] << endl;
  }
  cout << endl;

  for (int i=0;i<SIZE;i++) {
    avl->insert(v[i]);
    cout << "After Inserting " << v[i] << endl << endl;
    avl->print();
  }

  cout << "In Order Traversal: " << endl;
  avl->inOrderTraversal();
  cout << endl << "Post Order Traversal: " << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  for (int i=0;i<SIZE;i++) {
    avl->remove(v[SIZE-1-i]);
    cout << "After Removing " << v[SIZE-1-i] << endl << endl;
    avl->print();
  }

  delete avl;


/*
  AVL<int>* avl = new AVL<int>();
  avl->insert(1);
  avl->insert(2);
  avl->print();
  avl->insert(3);
  avl->print();
  avl->insert(4);
  avl->print();
  avl->insert(5);
  avl->print();
  avl->insert(6);
  avl->print();
  avl->insert(7);
  avl->print();
  avl->insert(8);
  avl->insert(9);
  avl->print();  
  avl->insert(10);
  avl->print();
  avl->inOrderTraversal();
  avl->postOrderTraversal();

  
  avl->remove(1);
  avl->print();  
  avl->remove(2);
  avl->print();  
  avl->remove(3);
  avl->print();  
  avl->remove(4);
  avl->print();
  avl->remove(5);
  avl->print();  
  avl->remove(6);
  avl->print();  
  avl->remove(7);
  avl->print();  
  avl->remove(8);
  avl->print();
  avl->remove(9);
  avl->print();
  avl->remove(10);
  avl->print();  

  avl->insert(5);
  avl->print();
  avl->insert(18);
  avl->print();
  avl->insert(25);
  avl->insert(2);
  avl->insert(1);
  avl->print();
  avl->remove(18);
  avl->print();
  delete avl;

  AVL<int>* a = new AVL<int>();
  a->insert(400);
  a->print();
  a->remove(5);
  a->print();
  a->remove(400);
  a->print();
  delete a;
*/

/*
  AVL<double>* d = new AVL<double>();
  d->insert(1);
  d->insert(2);
  d->insert(4);
  d->print();
  d->insert(3.5);
  d->insert(5);
  d->print();
  d->insert(3.25);
  d->print();

  delete d;

  AVL<int>* a1 = new AVL<int>();
  a1->insert(10);
  a1->insert(20);
  a1->insert(30);
  a1->insert(40);
  a1->print();
  a1->insert(35);
  a1->print();
  delete a1;

  AVL<int> a2;
  a2.insert(3);
  a2.insert(2);
  a2.insert(1);
  a2.insert(4);
  a2.print();
  a2.insert(5);
  a2.print();
  a2.insert(6);
  a2.print();
  a2.insert(7);
  a2.print();
  a2.insert(16);
  a2.print();
  a2.insert(15);
  a2.print();
  a2.insert(14);
  a2.print();
  a2.remove(7);
  a2.print();
  a2.remove(4);
  a2.print();
*/
/*
  AVL<double>* db=new AVL<double>();
  db->insert(7.5);
  db->insert(12.98);
  db->insert(3.45);
  db->insert(-2.58);
  db->insert(99.1);
  db->print();
  db->remove(12.98);
  db->remove(7.5);
  db->remove(5.34353);
  db->print();
  delete db;

  AVL<int>* b=new AVL<int>();
  b->insert(10);
  b->insert(5);
  b->insert(15);
  b->insert(1);
  b->insert(7);
  b->insert(11);
  b->insert(17);
  b->insert(18);
  b->insert(12);
  b->insert(14);
  b->insert(19);
  b->insert(8);
  b->insert(9);

  b->print();
 
  b->remove(15);
  b->remove(12);
  b->remove(10);
  b->print();
  b->remove(19);
  b->print();

  delete b;
*/

}