|
-
November 9th, 2009, 01:13 AM
#1
Hash Tables & Linked Lists
Hi,
I'm a java programmer and I have never used C++ before. But I have to code in C++ for an assignment. After all my research I managed to get this far and I'm totally lost. I'm supposed to implement hash tables and use linked list in the case of collisions. I would appreciate any help.
Thanks a ton.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
typedef string ObjectType;
struct ObjectNode{
ObjectType cars;
string model;
string status;
ObjectNode *next;
};
class LinkedList{
private:
ObjectNode *curNode, *headNode, *possitionNode;
public:
LinkedList(LinkedList& list);
void addRec(ObjectNode *&headNode, ObjectType cars, string status, string model);
bool isEmpty();
void printList();
};
LinkedList::LinkedList(LinkedList& list){
if(list.headNode == NULL)
headNode = NULL;
else{
headNode = new ObjectNode;
headNode->cars = list.headNode->cars;
ObjectNode *newNode = headNode;
for (ObjectNode *head = list.headNode->next; headNode != NULL; headNode = headNode->next)
{
newNode->next = new ObjectNode;
newNode = newNode->next;
newNode->cars = headNode->cars;
}
newNode->next = NULL;
}
}
void LinkedList::addRec(ObjectNode *&headNode, ObjectType cars, string status, string model){
if ((headNode == NULL) || (cars<headNode->cars))
{
ObjectNode *newNode = new ObjectNode;
newNode->cars = cars;
newNode->next = headNode;
cars<newNode->status;
cars<newNode->model;
headNode = newNode;
}
else
{
addRec(headNode->next, cars, status, model);
}
}
void LinkedList: rintList(){
ObjectNode *temp;
temp = new ObjectNode;
cout << temp->status;
cout << temp->model;
}
class HashTable{
public:
ObjectNode *indexNode;
LinkedList Table[26];
int size;
//Functions
HashTable();
void add(string newObject);
};
HashTable::HashTable(){
}
void HashTable::add(string newObject){
int index = getIndex(newObject);
indexNode = &T[index];
//indexNode.addRec(string newObject);
size++;
}
int main(){
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|