| | |
Creating an array of linked lists -- seg fault :'(
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 0
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
Thank you very much! I hope it's not too confusing to read. =\ Thanks!
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
{
public:
BucketHashTable();
~BucketHashTable();
void insert(GrabStuff);
private:
List <GrabStuff> *bucket[];
};
BucketHashTable::BucketHashTable()
{
for(int i = 0; i < 52; i++)
bucket[i] = new List<GrabStuff>();
}
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;
ListItr<GrabStuff> myIterator = bucket[index]->zeroth();
bucket[index]->insert(g, myIterator);
}Thank you very much! I hope it's not too confusing to read. =\ Thanks!
Last edited by crystality; 23 Days Ago at 1:47 am.
1
#2 23 Days Ago
try :
instead of:
C++ Syntax (Toggle Plain Text)
private: List <GrabStuff> *bucket[];
instead of:
C++ Syntax (Toggle Plain Text)
List <GrabStuff> bucket[];
PEACE !
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 0
0
#3 23 Days Ago
@ abhi_elementx: Thanks for your reply, but my code *does* use
I've tried the other way too. Still doesn't work. =\ Thanks though...
C++ Syntax (Toggle Plain Text)
private: List <GrabStuff> *bucket[];
I've tried the other way too. Still doesn't work. =\ Thanks though...
Last edited by crystality; 23 Days Ago at 1:55 am.
1
#4 23 Days Ago
specify a size while declaring the array:
you can later 'push' elements to the end of the list.
C++ Syntax (Toggle Plain Text)
List <GrabStuff> *bucket[52];
you can later 'push' elements to the end of the list.
PEACE !
![]() |
Similar Threads
- Merge sort using linked lists (C++)
- Arrays of linked lists - help! (C)
- seg fault when accessing the array (C)
- Seg Fault ~ Linked List Delete (C)
- Bug when creating linked lists in Dev C++ (C++)
- Seg Fault (C++)
Other Threads in the C++ Forum
- Previous Thread: Matrix multiplication
- Next Thread: Linked list
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





