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 4599884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:36:19+00:00 2026-05-21T23:36:19+00:00

For some reason, the value of the first element of the bucket array is

  • 0

For some reason, the value of the first element of the bucket array is being initialized to the size of the array, and growing in size after function calls.

Header file:

#ifndef TABLE
#define TABLE

#include <iostream>
#include <cstdlib>

typedef struct {
    double successful , unsuccessful[2] ;
} Perform ;

using namespace std ;

template <class DATA>
class Table {
private :
    DATA bucket[];
    bool passbit[];
    bool isFull[];
    unsigned tableSize;
    unsigned currentSize;
    unsigned sProbes;
    unsigned pbCount;

public :
    explicit Table ( unsigned size = 5 ) ;
    void clear ( ) ;
    //bool insert ( DATA & data ) ;
    bool insertD ( DATA & data ) ;
    //bool fetch ( DATA & data ) const ;
    bool getData ( unsigned i , DATA & data , bool & apassbit ) const ;
    //Perform perform ( ) const ;
};

#endif

I’m only using the constructor and one function for now, but I will include everything.

#include <typeinfo>
#include <queue>
#include <iostream>

#include "table.hpp"

using namespace std ;

template <class DATA>
Table<DATA> :: Table ( unsigned size ) 
{
    tableSize = size;
    currentSize = 0;
    sProbes = 0;
    pbCount = 0;
    bucket[tableSize];
    cout << bucket[0] << "\n";
    passbit[tableSize];
    isFull[tableSize];
}

template <class DATA>
void Table<DATA> :: clear()
{
    currentSize = 0;
    sProbes = 0;
    pbCount = 0;
    for (int i = 0; i < tableSize; i++)
    {
        bucket[i] = 0;
        passbit[i] = false;
        isFull[i] = false;
    }
}

template <class DATA>
bool Table<DATA> :: insertD ( DATA & data )
{
    cout << bucket[0] << "\n";
    unsigned value = unsigned ( data );
    unsigned index = value % tableSize;
    unsigned step = value % (tableSize - 2) + 1;
    while ( isFull[index] && !(bucket[index] == data) )
    {
        passbit[index] = true;
        pbCount++;
        index -= step;
        if ( index < 0 )
            index += tableSize;
    }
    if ( isFull[index] && (bucket[index] == data) )
        return false;
    else
    {
        bucket[index] = data;
        isFull[index] = true;
        currentSize++;
        return true;
    }
}

template <class DATA>
bool Table<DATA> :: getData ( unsigned i , DATA & data , bool & apassbit ) const
{
    if( bucket[i] != 0 )
    {
        data = bucket[i];
        apassbit = passbit[i];
        return true;
    }
    else
        return false;
}

Main function:

#include <iostream>
#include "table.cpp"
#include "table.hpp"

int main()
{
    Table<int> table = Table<int>();
    int i = 1;
    int ii = 2;
    int iii = 3;
    int iv = 4;
    int v = 5;
    table.insertD(i);
    table.insertD(ii);
    table.insertD(iii);
    table.insertD(iv);
    table.insertD(v);
    return 0;
}

Output:

5
5
261
65797
16843013
Segmentation fault

  • 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-05-21T23:36:19+00:00Added an answer on May 21, 2026 at 11:36 pm

    The problem is that you are trying to initialize statically allocated arrays. You need to either use dynamically allocated arrays or declare your statically allocated arrays big enough to hold all the data you will need. Of course, since you are using c++, you should consider using STL vectors.

    Here’s how you will need to adjust your code:

    class SomeClass
    {
        private:
            double* someArray;
            int     someArraySize;
    
        public:
            SomeClass( int arraySize )
            {
                someArray = new double[arraySize];
            }
    
            ~SomeClass()
            {
                delete [] someArray;
            }
    };
    

    This uses dynamic allocation. Notice that you need to delete the array when a class instance is destructed.

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

Sidebar

Related Questions

the following code for some bizarre reason gives me a value for each row
For some reason there's a variable called d that is defined immediately after I
For some reason I only get to the first option when I alert out
for some reason $post is always < 0. The indoxOf function works great. I
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason I can't detect I can't set a z index for any
For some reason the postback event keeps firing for my button. If I place
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
For some reason, the Google API expects longs instead of objects (like Color). What

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.