Click here to Skip to main content
15,918,333 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: already defined in .obj Pin
Programm3r12-Apr-07 22:41
Programm3r12-Apr-07 22:41 
QuestionHow to add data to a grid [modified] Pin
engilela12-Apr-07 21:20
engilela12-Apr-07 21:20 
QuestionLinker Error Pin
Programm3r12-Apr-07 19:59
Programm3r12-Apr-07 19:59 
AnswerRe: Linker Error Pin
Programm3r12-Apr-07 20:02
Programm3r12-Apr-07 20:02 
AnswerRe: Linker Error Pin
Arman S.12-Apr-07 20:06
Arman S.12-Apr-07 20:06 
GeneralRe: Linker Error Pin
Programm3r12-Apr-07 20:13
Programm3r12-Apr-07 20:13 
Questionsplit file by play length Pin
anu jaggi12-Apr-07 18:59
anu jaggi12-Apr-07 18:59 
AnswerRe: split file by play length Pin
Arman S.12-Apr-07 20:23
Arman S.12-Apr-07 20:23 
Questionicon disappears in win 2k Pin
ghunzel0612-Apr-07 17:25
ghunzel0612-Apr-07 17:25 
AnswerRe: icon disappears in win 2k Pin
Arman S.12-Apr-07 20:18
Arman S.12-Apr-07 20:18 
QuestionDevice List Pin
Xarzu12-Apr-07 16:11
Xarzu12-Apr-07 16:11 
AnswerRe: Device List Pin
bob1697212-Apr-07 16:27
bob1697212-Apr-07 16:27 
Questionfile input help Pin
Ackmm712-Apr-07 16:08
Ackmm712-Apr-07 16:08 
AnswerRe: file input help Pin
CPallini12-Apr-07 20:56
mveCPallini12-Apr-07 20:56 
QuestionAccessing CView from CDialog MFC??? Pin
bimgot12-Apr-07 15:24
bimgot12-Apr-07 15:24 
AnswerRe: Accessing CView from CDialog MFC??? Pin
bob1697212-Apr-07 16:44
bob1697212-Apr-07 16:44 
GeneralRe: Accessing CView from CDialog MFC??? Pin
ksrameshkanth12-Apr-07 19:35
ksrameshkanth12-Apr-07 19:35 
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!

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.