墨爾本代寫-線上編程學術專家

Best代寫-最專業靠譜代寫IT | CS | 留學生作業 | 編程代寫Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代寫

C語言代寫 | CSCI-UA.0201 Programming Assignment 1

C語言代寫 | CSCI-UA.0201 Programming Assignment 1

這個作業是用C語言構建一個哈希表和一個二進制搜索樹

CSCI-UA.0201
Programming Assignment 1

This programming assignment is to be done entirely in C. It will give you practice using pointers
and structs in C, in this case to build a hash table and a binary search tree.
As described below, you will be submitting three files, hashing.c, tree.c, and tree.h. To do so,
just upload the three files to the “Programming Assignment 1” page under the Assignments tab.
Important: Do not submit the files until the program is fully working. Although there is a modest
late penalty, you will lose far more points if you submit a program that doesn’t work.
This assignment looks long (5 pages), but that is only because I have given very detailed
instructions. That being said, please start working on the assignment immediately! If you have
general questions about this assignment, please post them on the class forum and I will answer
quickly. If you have questions about your code, please send them to the course assistant or coinstructor you were assigned to. Do not post your code to the forum.
You should complete the assignment by performing the following steps.
Step 1
In a file hashing.c, do the following:
? Declare a struct type HASHCELL, which is used to contain data in a hash table. A
HASHCELL should contain two fields: a word field that is a string – it should be of type
char *, so it’s a pointer, not an allocated array – and a next field that is a pointer to a
HASHCELL, so that HASHCELLs can be linked together in a list.
? Declare a global variable hashtable, representing a hash table, which is an array of
HASHCELL pointers. You should use #define to define a constant SIZE to be 100 and
declare hashtable to have SIZE elements.
? Define a function hash_string which takes a string (a char *) as a parameter and
returns an unsigned integer between 0 and SIZE -1, by hashing the string. You are free
to choose your own hash algorithm, but here is a simple one you can use:
o Define an unsigned integer variable hash and initialize it to 1.
o In a loop that iterates over each character in the string, set hash equal to
(hash * 7) + c in each iteration of the loop, where c is the current character.
Since a char is just an 8-bit number, so it’s fine to do arithmetic on it.
o Return the value of hash mod SIZE (where % is the mod operator).
Remember that you can recognize the end of a string by the terminating 0.
The quality of the hash (i.e., how evenly it distributes hash values between 0 and
SIZE – 1) isn’t so important here.
? Define a function insert_hash_cell that takes a string (again, a char *) as a
parameter and inserts the string into the hash table as follows:
o It calls hash_string on the string, assigning the result of the hash to an
unsigned integer variable index.
o It creates a HASHCELL (using malloc), such that the word field of the cell points
to the string. IMPORTANT: You will need to make a copy of the string by
performing the following steps:
§ Using malloc again, allocate a block of memory large enough to hold the
string (including the 0 at the end). I suggest using the built-in strlen
function, described at the bottom of this assignment, which gives you the
length of a string without the 0 at the end (so you’ll need to add 1).
§ Set the word field of the cell to point to the new block of memory.
§ Copy the characters of the string into the new block. I suggest using the
strcpy function, described at the bottom of this assignment.
o It inserts the new cell into the linked list of cells pointed to by
hashtable[index]. However, if the word in the new cell already exists in that
linked list, do not insert the new cell. This prevents duplicate words from being
inserted into the hash table. I suggest using the built-in strcmp function,
described below, to compare two strings to see if they are the same.
? Define a function print_hash_table() that prints out the elements of the hash table.
Specifically, in a loop, for each i from 0 to SIZE-1, the function should print out i, then
“:”, then (on the same line) all the words in the linked list at hashtable[i], and then a
carriage return. This way, the list of words at each element of the hash table is printed on
their own line.
Step 2
Still within hashing.c, define a main function that does the following:
? It declares a variable str that is an array of 100 chars (which should be large enough to
hold any string that is read in from the terminal).
? In a loop, it uses scanf to repeatedly read a string from the terminal into str, and then
calls insert_hash_cell on str to insert the string into the hash table (which is why
insert_hash_cell has to make a copy of the string). The loop should stop when
there are no more strings to read, which scanf will indicate by returning the value EOF.
That is, your loop could look like,
while (scanf(…) != EOF) {…}”.
? It calls print_hash_table()to print the contents of the hashtable.

Essay_Cheery

評論已關閉。

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信
北美代写,论文Essay代写,留学作业代写,-北美最专业的代写专家 堪培拉代写assignment,论文代写,留学作业代写-peaking代写 essay代写,assignment代写,留学生作业代写网课代做-锐 泽 代写 阿德莱德代写assignment,北美网课代修领导者,留学生网课代修代考 珀斯代写assignment,CS代写,留学生CS程序代写-Custom Writing代写 新西兰代写,math代写,新西兰Assignment代写-美 伦 代写 怎么样? 留学生CS代写,Java编程代写,网课代上代修-ezace留学生代写 达尔文代写assignment,留学生作业代写,留学代写-菠萝 菠萝蜜 代写 代写assignment,网课代上代考,考试代考论文代写-全球最好的华人代写机构 留学生代写,经济代写,代写作业-【靠谱】服务澳洲加拿大英国美国等地区