Question
Please write c language. typedef struct { int customer_no; char name[20], surname[20]; } Customer; Records in the above structure and whose information is kept in
Please write c language.
typedef struct {
int customer_no;
char name[20], surname[20];
} Customer;
Records in the above structure and whose information is kept in the "data.txt" file will be indexed according to the customer number.
For customer information, a 10-size data_list array will be created in the data type "Customer *". --> Customer *data_list[10];
As the data is added, the address of the "Customer" type structure will be assigned to the element in the index calculated as below (hash) in the data_list array.
For the hash table, a separate array of type int with size 10, hash_table array will be created. Except for the customer number in the hash_table array, a next value will be kept showing the hash index to be searched in case of conflict. In the hash_table, all values (customer_id and next) will initially be "1".
--> int hash_table[10][2];
Values to keep in the table
hash_table[x][0] ---- > customer_no
hash_table[x][1] ---- > next
According to this:
1-Adding Process: The adding process can be done over the records in the "data.txt" file and by the user on the screen. When the program is first opened, a hash_table will be created for the records in the "data.txt" file as described below and the data will be added to the data_list array according to the index in the hash table.
The hash function you will write will be determined as the value remaining from division of customer number by 10 (customer_no % 10) and the customer number will be saved to that index in the hash_table (if there is no conflict, the next value will remain as -1).
For example, if the customer number is 2214, the hash index will be 4.
Each time a customer number is added to the hash table, customer information will be added to the same index of the data_list.
If there is a conflict, it will be recorded in the first empty space in the hash_table and will add the index value it received to the field showing the next value in the index with the conflict. If there is a conflict and another next value is written here (if it is not -1), it will follow the next number entered before from the hash_table and write the value of the index it gets in the field with the first next value -1.
When the Hash Table is full, no further additions will be made by giving the message "table is full".
2-Search Process: In the search process, if the number in the hash index (customer_no % 10) calculated from the customer number entered by the user is the same as the customer number (in hash_table), the information in the calculated index of the data list will be printed on the screen and the number of steps it reaches (1 if it is the first one) will be printed on the screen.
If it is not the same as the customer number, it will try to find the customer number by following the next "next" values (the function can return what it found in the step). If the location it is looking at is not the same as the customer number and the next value is -1, it will be printed as "Not Found" (the function may return -1 value).
- Deletion Process: Information about the customer number entered by the user will be deleted from the hash_table and data list. Since the index of the deleted data will remain empty, another data can be added later. In the process of deleting, the next values that previously enabled access to other data will not change.
4-Hash table listing: The created has_table array will be regularly printed on the screen.
5-Listing the data list: The data added to the created data_list array will be listed on the screen in an orderly order according to the order in the array.
6-Average Number of Steps: Average number of steps reached to all records (non-empty) will be printed on the screen.
Note: There will be a main menu for actions and will return to the main menu after each action.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started