Hello! I'm getting this infamous problem: Segmentation fault (core dumped). Not sure what's going on. ='( Please help! I've red-ed and bolded the parts that I think are problems.

In the following class, I'm trying to create a class called 'BucketHashTable'. I want to create an array of known size (size 52), which contains linked lists. (So I'm trying to create 52 linked lists.) In each of the linked lists, I want to be able to insert an unknown # of objects called 'GrabStuff'. Later, I will want to sort objects inside each individual linked list, but I'm not there yet.

By the way, that class is trying to do a sort-of 'hash' with word inside the 'GrabStuff' object. I'm 'hashing' the first letter of the word, and then putting the corresponding object into appropriate linked list. =| If that makes sense.

Relevant links/files: LinkedList.cpp | LinkedList.h | My entire code so far
Other included files: QuadraticProbing.cpp | QuadraticProbing.h | string.cpp | mystring.h

class BucketHashTable
		void insert(GrabStuff);
		List <GrabStuff> *bucket[];

[B]	for(int i = 0; i < 52; i++)
		bucket[i] = new List<GrabStuff>();[/B]

BucketHashTable::~BucketHashTable() {}

void BucketHashTable::insert(GrabStuff g)
	int ascii = (int)g.getWord()[0];
	int index = 0;
	if (ascii <= 90)		// if uppercase
		index = ascii%65;
	else 				// if lowercase
		index = ascii%97;
	[B]ListItr<GrabStuff> myIterator = bucket[index]->zeroth();
	bucket[index]->insert(g, myIterator);[/B]

Thank you very much! I hope it's not too confusing to read. =\ Thanks!

Edited by crystality: n/a

7 Years
Discussion Span
Last Post by abhi_elementx

@ abhi_elementx: Thanks for your reply, but my code *does* use

		List <GrabStuff> *bucket[];

I've tried the other way too. Still doesn't work. =\ Thanks though...

Edited by crystality: n/a


specify a size while declaring the array:

List <GrabStuff> *bucket[52];

you can later 'push' elements to the end of the list.

Votes + Comments
THANK YOU! It works!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.