Click here to Skip to main content
15,905,414 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Accessing CView from CDialog MFC??? Pin
bimgot13-Apr-07 2:30
bimgot13-Apr-07 2:30 
GeneralRe: Accessing CView from CDialog MFC??? Pin
JudyL_MD13-Apr-07 2:46
JudyL_MD13-Apr-07 2:46 
GeneralRe: Accessing CView from CDialog MFC??? Pin
bob1697213-Apr-07 3:22
bob1697213-Apr-07 3:22 
GeneralRe: Accessing CView from CDialog MFC??? Pin
bimgot15-Apr-07 13:17
bimgot15-Apr-07 13:17 
QuestionCorrect way to remove old unused symbol? Pin
maxmaven12-Apr-07 11:23
maxmaven12-Apr-07 11:23 
AnswerRe: Correct way to remove old unused symbol? Pin
Ravi Bhavnani12-Apr-07 11:34
professionalRavi Bhavnani12-Apr-07 11:34 
GeneralRe: Correct way to remove old unused symbol? Pin
dburns12-Apr-07 17:10
dburns12-Apr-07 17:10 
QuestionDouble linked list is overwriting string items Pin
Yustme12-Apr-07 10:38
Yustme12-Apr-07 10:38 
Hi,

I made a program which hashes string items in a table. The table has 5 index positions.

When the table is full with string items, the linked list is overwriting the existing string items.

This is my code from Table:


Table::Table(int listSize)
{
size = listSize;
list = new List[size];
}

// hash function
int Table::hash(string item)
{
unsigned int hval, g;
char *str = &item[0];

/* Compute the hash value for the given string. */
hval = 0;
while (*str != '\0')
{
hval <<= 4;
hval += (unsigned int) *str++;
g = hval & ((unsigned int) 0xf << (HASHWORDBITS - 4));
if (g != 0)
{
hval ^= g >> (HASHWORDBITS - 8);
hval ^= g;
}
}

return hval%size;
}

Node* Table::find(string item)
{
int hashValue = hash(item);
return list[hashValue].find(item);
}

Node* Table::insert(string item)
{
int hashValue = hash(item);
return list[hashValue].insert(item);
}

bool Table::isMember(string item)
{
int hashValue = hash(item);
return (list[hashValue].find(item) != NULL);
}

void Table::remove(string item)
{
int hashValue = hash(item);
list[hashValue].remove(item);
}

void Table::print()
{
for(int index = 0; index < size; index++)
{
cout << "Index: " << index << ": ";
list[index].print();
cout << endl;
}
}


The double linked list class:

List::List()
{
head = NULL;
}

List::~List()
{
Node* previousNode;
Node* node = head;

while(node != NULL)
{
previousNode = node;
node = node->next;
delete previousNode;
}
}

Node* List::insert(string item)
{
head = new Node(head, item);
return head;
}

void List::remove(string item)
{
Node* previousNode;
Node* node = head;

while(node != NULL)
{
if(head->value == item)
{
// Link previous node to next node
if(previousNode != NULL)
previousNode->next = node->next;
else
head = node->next;

delete node;
break;
}

previousNode = node;
node = node->next;
}
}

Node* List::find(string item)
{
Node* previousNode;
Node* node = head;

while(node != NULL)
{
if(head->value == item)
return node;

previousNode = node;
node = node->next;
}

return NULL;
}

void List::print()
{
Node* node = head;

if(node != NULL)
{
cout << node->value << " ";
node = node->next;
}

cout << endl;
}


Node class:

Node::Node(Node* n, string s)
{
next = n;
value = s;
}

The Table with the hashed string items im trying to make should look for example like this:

Index 1: string23, string5, string11, etc...
Index 2: string9, string1,
Index 3: .......

The table has to be balanced a bit.

Can somebody tell me what is going wrong in my double linked list?

Thanks in advance!

AnswerRe: Double linked list is overwriting string items Pin
cp987612-Apr-07 14:15
cp987612-Apr-07 14:15 
GeneralRe: Double linked list is overwriting string items Pin
Yustme13-Apr-07 2:16
Yustme13-Apr-07 2:16 
QuestionNew to VS 2005 - How do I switch between C++ to C#? Pin
huehue12-Apr-07 8:54
huehue12-Apr-07 8:54 
AnswerRe: New to VS 2005 - How do I switch between C++ to C#? Pin
led mike12-Apr-07 9:23
led mike12-Apr-07 9:23 
AnswerRe: New to VS 2005 - How do I switch between C++ to C#? Pin
huehue12-Apr-07 10:45
huehue12-Apr-07 10:45 
AnswerRe: New to VS 2005 - How do I switch between C++ to C#? Pin
George L. Jackson12-Apr-07 11:15
George L. Jackson12-Apr-07 11:15 
GeneralRe: New to VS 2005 - How do I switch between C++ to C#? Pin
huehue12-Apr-07 11:29
huehue12-Apr-07 11:29 
GeneralRe: New to VS 2005 - How do I switch between C++ to C#? Pin
George L. Jackson12-Apr-07 11:42
George L. Jackson12-Apr-07 11:42 
QuestionHow To Load Google Toolbar For Dialog Pin
MyNothing12-Apr-07 7:10
MyNothing12-Apr-07 7:10 
AnswerRe: How To Load Google Toolbar For Dialog Pin
Reagan Conservative12-Apr-07 9:35
Reagan Conservative12-Apr-07 9:35 
Questioninstalling a program i've made Pin
Tully200312-Apr-07 6:45
Tully200312-Apr-07 6:45 
AnswerRe: installing a program i've made Pin
Mark Salsbery12-Apr-07 7:12
Mark Salsbery12-Apr-07 7:12 
AnswerRe: installing a program i've made Pin
Maximilien12-Apr-07 8:32
Maximilien12-Apr-07 8:32 
AnswerRe: installing a program i've made Pin
Ravi Bhavnani12-Apr-07 11:36
professionalRavi Bhavnani12-Apr-07 11:36 
AnswerRe: installing a program i've made Pin
sanket.patel12-Apr-07 16:03
sanket.patel12-Apr-07 16:03 
QuestionTrying to understand VS AddIns Pin
dburns12-Apr-07 6:28
dburns12-Apr-07 6:28 
QuestionIs possible to allocate strictly physical mem.(RAM) instead of virtual (page file) Pin
marcelse12-Apr-07 4:37
marcelse12-Apr-07 4:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.