Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:05:01+00:00 2026-06-02T01:05:01+00:00

I’m trying to implement a templated priority queue using a heap to process frequencies

  • 0

I’m trying to implement a templated priority queue using a heap to process frequencies of pixels in an image. It works fine, but when I try to use it by passing another class as the template argument, it ends up converting the class to a pointer to the class while trying to reheap down or up. Here is the heap specification:

template <typename ItemType>
struct HeapType
{
    void ReheapDown(int, int);
    void ReheapUp(int, int);
    ItemType *elements;
    int numElements;
};

reheap down function:

template<typename ItemType>
void HeapType<ItemType>::ReheapDown(int root, int bottom)
{
    int maxChild, rightChild, leftChild;
    leftChild = 2*root+1;
    rightChild = 2*root+2;

    if(leftChild <= bottom)
    {
        if(leftChild == bottom)
        {
            maxChild = leftChild;
        }
        else
        {
            if(elements[leftChild] <= elements[rightChild])
                maxChild = rightChild;
            else
                maxChild = leftChild;
        }
        if(elements[root] < elements[maxChild])
        {
            Swap(elements, root, maxChild);
            ReheapDown(maxChild, bottom);
        }
    }
}

and Swap funciton:

template<typename ItemType>
void Swap(ItemType &itemSwap, int swapFrom, int swapTo)
{
    ItemType tempItem;
    tempItem = itemSwap[swapFrom];
    itemSwap[swapFrom] = itemSwap[swapTo];
    itemSwap[swapTo] = tempItem;
}

So, I have the Priority queue being implemented using a helper class called Pfreq that overloads the comparison operators so that the heap sorts by frequency of the pixel rather than the value of the pixel. It has no problem until it gets to the Swap function and then complains that it can’t convert the type from Pfreq to Pfreq*. I’m not entirely sure how to solve the problem that the template causes the Swap function to be called with type Pfreq*.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:05:03+00:00Added an answer on June 2, 2026 at 1:05 am

    I think the issue is in the declaration of this function:

    template<typename ItemType>
        void Swap(ItemType &itemSwap, int swapFrom, int swapTo)
    

    You’re trying to use the first argument as an array, as evidenced here:

    ItemType tempItem;
    tempItem = itemSwap[swapFrom];
    itemSwap[swapFrom] = itemSwap[swapTo];
    itemSwap[swapTo] = tempItem;
    

    The problem is that itemSwap is a reference to an ItemType, not an array of ItemTypes or a pointer to an ItemType. Try changing that parameter to be an ItemType* and see if that fixes things.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.