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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:50:29+00:00 2026-06-04T13:50:29+00:00

For starters my program is to create a hash table of names where collison

  • 0

For starters my program is to create a hash table of names where collison is handled by chaining.
So i create an array of Linked List. Problem is my array is very large 88801 to be exact. Im thinking thats why im getting a stack over flow but im not sure. My code is below. Some one tried telling me to make the array a set of pointers to linked list.
IE putting LinkedList* hashbucket1[88801] which this removed the stack overflow issue but caused other linking errors. Guess im trying to figure out what is the best way to impliment an array of linked list of strings. If im on the right track and its something small im over looking please point it out or tell me to scrap this and start over with a given path in mind. If i need to link or zip up my other files let me know and i can.

#include <iostream>
#include "LinkedList.h"
#include <string>
#include <fstream>

using namespace std;

 unsigned long djb2(string& str) 
 { 
 unsigned long hash = 5381; 

  for(string::iterator it = str.begin();it!=str.end();it++)  
    hash = ((hash << 5) + hash) + *it; /* hash * 33 + character */ 

 return hash; 
 }

  static unsigned long sdbm(string& str)
{
    unsigned long hash = 0;
    int c;

   for(string::iterator it = str.begin();it!=str.end();it++)
        hash = *it + (hash << 6) + (hash << 16) - hash;

    return hash;
  }


  void insert(LinkedList HashList1[], LinkedList HashList2[], int listSize);

    int main() {
char command;
int listSize = 88801;
LinkedList HashList1[88801];
LinkedList HashList2[88801];
bool invalidcommand;
do{
    do{
        cout << "MENU" << endl;
        cout << "(I)nsert new entry" << endl;
        cout << "(S)earch" << endl;
        cout << "(D)elete Entry" << endl;
        cout << "(C)reate Hast Table" << endl;
        cout << "(L)og File" << endl;
        cout << "(Q)uit and Exit Program" << endl;

        cin >> command;

    if(command == 'I'){
        insert(HashList1, HashList2, listSize);
    }else if(command == 'S'){
  //            search(HashList1, HashList2, listSize);
    }else if(command == 'D'){

    }else if(command == 'L'){ 
    //  save(HashList1, HashList2, listSize);
    }else if(command == 'C'){
    //  load(HashList1, HashList2, listSize);
    }
}while(command != 'Q');

return 0;
    };

    void insert(LinkedList HashList1[], LinkedList HashList2[], int listSize){

string lastName;
bool invalidID;
//Person newPerson;
do
{
    invalidID = false;
    cout << "Please enter Last Name: ";
    cin >> lastName;
    while(cin.fail())
    {
        cin.clear();
        cin.ignore();
    }
}while(invalidID);
//newPerson.setLastName(lastName);
int hashBucket1;
int hashBucket2;
hashBucket1 = djb2(lastName) % listSize;
hashBucket2 = sdbm(lastName) % listSize;
LinkedList bucket1;
if(!HashList1[hashBucket1].find(lastName)){     
    //HashList1[hashBucket1].insert(newPerson);
    HashList1[hashBucket1].insert(lastName);

}else{
    if(!bucket1.find(lastName)){

        HashList1[hashBucket1].insert(lastName);
    }else{
    cout << "List already contains an entry with the last name " << lastName << endl;
    }
}
LinkedList bucket2;
if(HashList2[hashBucket2].find(lastName)){
//  bucket2.insert(newPerson);
}else{
    if(!bucket2.find(lastName)){
        //bucket2.insert(newPerson);
    }else{
    cout << "List already contains an entry with the last name " << lastName << endl;
    }
}
   }
  • 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-04T13:50:30+00:00Added an answer on June 4, 2026 at 1:50 pm

    Your problem, as you correctly suspect, is that you are running out of stack space. You shouldn’t be placing such big objects on the stack, which is a limited and precious resource. Instead, you can use pointers and allocate them dynamically on the heap.

    The problematic code is here:

    int main() {
    char command;
    int listSize = 88801;
    LinkedList HashList1[88801]; // << this
    LinkedList HashList2[88801]; // << and this
    

    also note that LinkedList* hashbucket1[88801] is an array of pointers, not a pointer to an array. What you want is:

    LinkedList (*HashList1)[88801]
    

    or, with typedef to make it more readable:

    typedef LinkedList LinkedListArray[88801];
    LinkedListArray* HashList1;
    

    but by then it would be better to just do:

    LinkedList *HashList1 = new LinkedList[88801];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, just for starters, I am very new to Objective-C, (C in general). I
Hello I want to create a dll with some functions. For starters I'm trying
I want to create my very first web app using HTML, MySQL, PHP and
for starters: I searched for hours on this problem by now - so if
For starters, this question is not so much about programming in the NetBeans IDE
Ok, a few things I'm not quite sure about. For starters: I have a
In my simple starter asp page I create a DataTable and populate it with
Here's a starter list: if hbm is hand generated, is it an embedded resource?
For homework, I'm trying to create a CustomButton that has a frame and in
I have 2 applications communicating using named pipes. Main program calls client program and

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.