当前位置: 首页>>代码示例>>C++>>正文


C++ AVL::Delete方法代码示例

本文整理汇总了C++中AVL::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ AVL::Delete方法的具体用法?C++ AVL::Delete怎么用?C++ AVL::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AVL的用法示例。


在下文中一共展示了AVL::Delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main( void ) {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    AVL<segment> Tree;
    int n;
    cin >> n;
    vector<segment> seg;
    for (int i = 0; i < n; i++) {
        point pointOne, pointTwo;
        cin >> pointOne.x >> pointOne.y >> pointTwo.x >> pointTwo.y;
        seg.push_back(segment(pointOne, pointTwo));
    }

    vector<point_event> e;
    for (int i = 0; i < n; i++) {
        e.push_back(point_event(min(seg[i].pointOne.x, seg[i].pointTwo.x), 1, i));
        e.push_back(point_event(max(seg[i].pointOne.x, seg[i].pointTwo.x), -1, i));
    }
    sort(e.begin(), e.end());
    double val = numeric_limits<double>::max();
    segment zero(point(val, val), point(val, val));
    for (int i = 0; i < e.size(); i++) {
        int ind = e[i].ind;
        if (e[i].type == 1) {
            Tree.Add(seg[ind]);
            segment cur = Tree.Next(seg[ind]);
            if (!(cur == zero) && crossing(cur, seg[ind])) {
                cout << "Еть пересечение";
                return 0;
            }
            cur = Tree.Prev(seg[ind]);
            if (!(cur == zero) && crossing(cur, seg[ind])) {
                cout << "Есть пересечиние";
                return 0;
            }

        }
        else {
            segment cur = Tree.Next(seg[ind]);
            if (!(cur == zero) && crossing(cur, seg[ind])) {
                cout << "Еть пересечение";
                return 0;
            }
            cur = Tree.Prev(seg[ind]);
            if (!(cur == zero) && crossing(cur, seg[ind])) {
                cout << "Есть пересечиние";
                return 0;
            }
            Tree.Delete(seg[ind]);
        }
    }
    cout << "Нет пересечений";
    return 0;
}
开发者ID:kamiltalipov,项目名称:295-a2,代码行数:54,代码来源:main.cpp

示例2: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	//Binary Search Tree
	int bstArraySize = 11;		
	int bstArray[] = { 15, 6, 18, 3, 7, 17, 20, 2, 13, 4, 9 };
	cout << "BST Input Array: " ;
	PrintArray(bstArray, bstArraySize);

	BST myBST;
	for (int i = 0; i < bstArraySize; i++)
		myBST.Insert(myBST.root, bstArray[i]);

	cout << "InOrderTreeWalk: ";
	myBST.InOrderTreeWalk(myBST.root);
	cout << endl;

	cout << "PreOrderTreeWalk: ";
	myBST.PreOrderTreeWalk(myBST.root);
	cout << endl;

	cout << "PostOrderTreeWalk: ";
	myBST.PostOrderTreeWalk(myBST.root);
	cout << endl;

	myBST.Search(myBST.root, 100);
	myBST.Search(myBST.root, 20);
	myBST.Maximum(myBST.root);
	myBST.Minimum(myBST.root);
	myBST.SearchParent(myBST.root, 9);

	cout << "Delete Node 15: ";
	myBST.Delete(myBST.root, 15);	
	myBST.InOrderTreeWalk(myBST.root);
	cout << endl;
	cout << endl;

	//Max Heap
	int table[] = {16, 4, 10, 14, 7, 9, 3, 2, 8, 1, 0, 0, 0, 0};
	int heapSize = 10;
	int* maxHeapArray = new int[15];

	for (int i = 0; i < heapSize; i++)
		*(maxHeapArray + i) = table[i];
	cout << "Max-Heap: ";
	PrintArray(maxHeapArray, heapSize);
	MaxHeap myMaxHeap;
	myMaxHeap.MaxHeapify(maxHeapArray, heapSize, 1);
	cout << "Max-Heapified 1: ";
	PrintArray(maxHeapArray, heapSize);

	for (int i = 0; i < heapSize; i++)
		*(maxHeapArray + i) = table[i];
	cout << "Max-Heap: ";
	PrintArray(maxHeapArray, heapSize);
	myMaxHeap.BuildHeap(maxHeapArray, heapSize);
	cout << "BuildHeap: ";
	PrintArray(maxHeapArray, heapSize);
	cout << "HeapExtractMax: " << myMaxHeap.HeapExtractMax(maxHeapArray, heapSize) << endl;
	cout << "Remaining: ";		
	PrintArray(maxHeapArray, heapSize - 1);
	cout << "HeapInsert 32: \n";
	myMaxHeap.HeapInsert(maxHeapArray, heapSize - 1, 32);
	cout << "New Heap: ";
	PrintArray(maxHeapArray, heapSize);

	for (int i = 0; i < heapSize; i++)
		*(maxHeapArray + i) = table[i];
	cout << "Max-Heap: ";
	PrintArray(maxHeapArray, heapSize);
	myMaxHeap.HeapSort(maxHeapArray, heapSize);
	cout << "HeapSort: ";
	PrintArray(maxHeapArray, heapSize);
	cout << endl;

	//AVL tree
	int avlArraySize =11;
	//int avlArray[] = { 15, 6, 18, 3, 7, 17, 20, 2, 13, 4, 9 };
	int avlArray[] = { 30, 50, 40, 60, 70, 17, 20, 2, 13, 4, 9 };
	cout << "AVL Input Array: ";
	PrintArray(avlArray, avlArraySize);
	AVL myAVL;
	for (int i = 0; i < avlArraySize; i++)
	{
		myAVL.Insert(myAVL.root, avlArray[i]);
		myAVL.InOrderTreeWalk(myAVL.root);
		cout << endl;
	}

	cout << "Delete 30: \n";
	myAVL.Delete(myAVL.root, 30);
	myAVL.InOrderTreeWalk(myAVL.root);
	cout << endl;

	cout << "Delete 13: \n";
	myAVL.Delete(myAVL.root, 13);
	myAVL.InOrderTreeWalk(myAVL.root);
	cout << endl;

	cout << "Delete 20: \n";
	myAVL.Delete(myAVL.root, 20);
//.........这里部分代码省略.........
开发者ID:hblxtracy,项目名称:CrackingTheCodingInterview,代码行数:101,代码来源:Main.cpp


注:本文中的AVL::Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。