954,124 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Hash tables in pascal

Hi, i have an assignment that involves me making a hash table which stores strings. I am struggling to find a good example of a hash table anywhere and would be greatful if someone could give me an idea of the basic code or even pseudocode for it.

ineed to
initialise the table
display the table
search it
and insert to it

my data type is

<strong>type</strong> HTable = array [0 .. tableSize-1] of integer;


firstly- should it say string instead of integer?

my initialise procedure basically runs through the array assigning giving each item the value 0

<strong>procedure</strong> initialise(var h: HTable);
<strong>var</strong> i:integer;
<strong>begin</strong>
i:=0 ;
<strong>for</strong> i := 0 to tableSize-1 <strong>do</strong>
h[i]:= 0 ;
<strong>end</strong>;

is this correct and again should i be assigning everything a blank char ' ' ?

My display procedure is similar but it write to the screen

<strong>procedure</strong> display (h: HTable; filename: string);
<strong>var</strong> i:integer;
<strong>begin</strong>
i:=0  ;
<strong>for</strong> i := 0 to tableSize-1 <strong>do</strong>
<strong>begin</strong>
WriteLn ('#',i,': ',h[i]) ;
<strong>End</strong>;
<strong>end</strong>;

this is how i have started and my program compiles but when i choose to display the list nothing at all happens, i have done something terribly wrong here?

thansk alot

mynameisrich
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Hi, i have an assignment that involves me making a hash table which stores strings. I am struggling to find a good example of a hash table anywhere and would be greatful if someone could give me an idea of the basic code or even pseudocode for it.

ineed to initialise the table display the table search it and insert to it

my data type is

<strong>type</strong> HTable = array [0 .. tableSize-1] of integer;

firstly- should it say string instead of integer?

my initialise procedure basically runs through the array assigning giving each item the value 0

<strong>procedure</strong> initialise(var h: HTable);
<strong>var</strong> i:integer;
<strong>begin</strong>
i:=0 ;
<strong>for</strong> i := 0 to tableSize-1 <strong>do</strong>
h[i]:= 0 ;
<strong>end</strong>;

is this correct and again should i be assigning everything a blank char ' ' ?

My display procedure is similar but it write to the screen

<strong>procedure</strong> display (h: HTable; filename: string);
<strong>var</strong> i:integer;
<strong>begin</strong>
i:=0  ;
<strong>for</strong> i := 0 to tableSize-1 <strong>do</strong>
<strong>begin</strong>
WriteLn ('#',i,': ',h[i]) ;
<strong>End</strong>;
<strong>end</strong>;

this is how i have started and my program compiles but when i choose to display the list nothing at all happens, i have done something terribly wrong here?

thansk alot

If you will go here www.sparknotes.com/cs/searching/hashtables/section1.html
you will find an excelent explanation of what you are trying to do with good examples of how. If you need further help with your code after you read it, post back.
Good Luck,
Daunti

Daunti
Newbie Poster
2 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You