English 中文(简体)
C++ H树和点树
原标题:C++ Huffman Tree and Pointers
  • 时间:2010-09-23 04:22:27
  •  标签:
  • c++

我正在制造一颗Huffman树,为此,我首先制造了Min Heap。 肥皂的建立和按频率对数值进行分类,但我的问题在于我试图开始创造树木。

我正在冲破头两件 items子,把 no子放在前面,并重新插入。 肥皂是阵列,因此不会触及 *和des右点。 然而,如果跌落到只剩下一席之地,右铭就是无效的,那么我相信,它可能是一个与我方的问题。 我是把我的umb错误从java开出的。

 while(theHeap.getheapSize() > 1)
    {
        Node top;
        Node *min1=new Node(theHeap.topandPop());
        Node *min2=new Node(theHeap.topandPop());
        top.left=min1;
        top.right=min2;
        top.freq=min1->freq+min2->freq;
        theHeap.insert(top);
    }
    Node r=theHeap.topAndPop(); //null pointers for left and right children

--------------------------------------
    //code for heap.  arr is in the header file is Node *arr;

void Heap::insert(Node c)
{
    if (heapSize != arrSize)
    {
        heapSize=heapSize+1;
        arr[heapSize - 1] = c; //does this call copy constructor???
        percolateUp(heapSize - 1);
    }
}
void Heap::percolateUp(int nodeIndex) {

    int parentIndex;
    Node tmp;
    if (nodeIndex != 0)
    {
        parentIndex = getParentPos(nodeIndex);
        if (arr[parentIndex].freq > arr[nodeIndex].freq)
        {
            tmp = arr[parentIndex];
            arr[parentIndex] = arr[nodeIndex];
            arr[nodeIndex] = tmp;
            percolateUp(parentIndex);

        }
    }
}
问题回答

首先,我建议不要混淆事例和要点,如果你选择的话,你的任务将更加简单。 在本案中,我认为宜将一站点放在一站式,而不是一例,增加的好处是,点人的行为比 Java更像,不需要担心复印的施工和分配。 你们只需要记住删除这些字句(如在 Java),这是在海普勒可以做的事。

第二,在你的法典评论中回答问题: Heap没有援引任何影子:insert(),而是援引转让经营者。 这是否是一个问题,取决于贵诺贝尔阶层所看的情况。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签