示例#1
0
int main(){

    BinomialHeap<int> H;
    H.insert(0);
    H.insert(1);
    H.print();

    return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    BinomialHeap *bh = new BinomialHeap(comparaEnteros,sizeof(int));
    void *minimovalor = bh->getmin(sizeof(int));

    qDebug()<<"retorno "<<*((int *) minimovalor);
    
    return a.exec();
}
示例#3
0
文件: Binomial.cpp 项目: dil2/aa
/*
 * Main Contains Menu
 */
int main()
{
    int n, m, l, i;
    BinomialHeap bh;
    node* p;
    node *H;
    H = bh.Initializeheap();
    char ch;
    while (1)
    {
        cout<<"----------------------------"<<endl;
        cout<<"Operations on Binomial heap"<<endl;
        cout<<"----------------------------"<<endl;
        cout<<"1)Insert Element in the heap"<<endl;
        cout<<"2)Extract Minimum key node"<<endl;
        cout<<"3)Decrease key of a node"<<endl;
        cout<<"4)Delete a node"<<endl;
        cout<<"5)Display Heap"<<endl;
        cout<<"6)Exit"<<endl;
        cout<<"Enter Your Choice: ";
        cin>>l;
        switch(l)
        {
        case 1:
            cout<<"Enter the element to be inserted: ";
            cin>>m;
            p = bh.Create_node(m);
            H = bh.Insert(H, p);
            break;
        case 2:
            p = bh.Extract_Min(H);
            if (p != NULL)
                cout<<"The node with minimum key: "<<p->n<<endl;
            else
                cout<<"Heap is empty"<<endl;
            break;
        case 3:
            cout<<"Enter the key to be decreased: ";
            cin>>m;
            cout<<"Enter new key value: ";
            cin>>l;
            bh.Decrease_key(H, m, l);
            break;
        case 4:
            cout<<"Enter the key to be deleted: ";
            cin>>m;
            bh.Delete(H, m);
            break;
        case 5:
            cout<<"The Heap is: "<<endl;
            bh.Display(H);
            break;
        case 6:
            exit(1);
        default:
            cout<<"Wrong Choice";
	  }
    }
    return 0;
}
示例#4
0
void* crearNodo(void* address, int size)
{
    char* block = (char *)malloc(size);
    memcpy(block, address, size);

    garbageCollector.insert(block,size);
    return block;
}
示例#5
0
void assign(void ** destiny, void ** source)
{
    HeapNode<void*>* resultDestiny = garbageCollector.findNode(destiny);
    if(resultDestiny)
    {
        garbageCollector.decreaseKey(destiny, resultDestiny->pointedBy - 1);
        if(resultDestiny->pointedBy == 0)
        {
            garbageCollector.extractMin();
        }
    }
    HeapNode<void*>* resultSource = garbageCollector.findNode(source);
    if(resultSource)
    {
        garbageCollector.increaseKey(resultSource, 1);
    }
    destiny = source;

}
示例#6
0
int main()
{
    cout<<"Binomial Heap\n\n";
    BinomialHeap bh;
    char ch;
    int val;
        /*  Perform BinomialHeap operations  */
    do
    {
        cout<<"1. Insert "<<endl;
        cout<<"2. Delete "<<endl;
        cout<<"3. Size"<<endl;
        cout<<"4. Check empty"<<endl;
        cout<<"5. Clear"<<endl;
        int choice;
        cout<<"Enter your Choice: ";
        cin>>choice;
        switch (choice)
        {
        case 1 :
            cout<<"Enter integer element to insert: ";
            cin>>val;
            bh.insert(val);
            break;
        case 2 :
            cout<<"Enter element to delete: ";
            cin>>val;
            bh.Delete(val);
            break;
        case 3 :
            cout<<"Size = "<<bh.getSize()<<endl;
            break;
        case 4 :
            cout<<"Empty status = ";
            if (bh.isEmpty())
                cout<<"Heap is empty"<<endl;
            else
                cout<<"Heap is non - empty"<<endl;
            break;
        case 5 :
            bh.makeEmpty();
            cout<<"Heap Cleared\n";
            break;
        default :
            cout<<"Wrong Entry \n ";
            break;
        }

        /* Display heap */
        bh.displayHeap();
        cout<<"\nDo you want to continue (Type y or n) \n";
        cin>>ch;
    }
    while (ch == 'Y'|| ch == 'y');
    return 0;
}