summaryrefslogtreecommitdiff
path: root/src/02/04/main.c
blob: 4dacb08fb42cff259d0e1c480b47fbf73e395833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "hash.h"
#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("=== COMP-272 - Assignment 02 - Question 04 ===\n");
  Hash *hash = hash_init(13);
  int items[] = {1, 5, 21, 26, 39, 14, 15, 16, 17, 18, 19, 20, 111, 145, 146};
  int n = sizeof(items) / sizeof(int);

  printf("Insert items into hash\n");
  for (int i = 0; i < n; i++) {
    int key = items[i];
    long value = key * 10;
    printf("(%d:%d) ", key, value);
    hash_set(hash, key, (void *)value);
  }

  printf("\nInspect hash table\n");
  hash_inspect(hash);

  printf("Retrieve each item from the table\n");
  for (int i = 0; i < n; i++) {
    int key = items[i];
    printf("(%d:%d) ", key, hash_get(hash, key));
  }

  printf("\nBye\n");
  return 0;
}