https://github.com/r100-stack/saving-heap-position-using-hash-table
https://github.com/r100-stack/saving-heap-position-using-hash-table
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/r100-stack/saving-heap-position-using-hash-table
- Owner: r100-stack
- Created: 2020-11-16T19:27:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-16T23:21:20.000Z (over 5 years ago)
- Last Synced: 2025-01-01T07:08:00.013Z (over 1 year ago)
- Language: C
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Saving Heap Position Using Hash Table
Sample that implements a heap and saves the location of the elements in a hash table.
As many of you may not be familiar with C, you may find it difficult to understand. Hence, I would recommend you don't go through the entire code. Instead just try to understand the main idea the program does by following the video.
**[Video recording of SI session that discusses the programming assignment # and the sample code in more detail](https://lsu.zoom.us/rec/share/dOujfHXyBQmCz_hNVoDRIWXzGKHibUcT5sjggIKlyIMaYaNOocWzsQroxVWdwtel.38OR-bmhZCiNKUkL)**
## How to run the code (Mac/Linux)
```
chmod +x ./compile.sh
./compile.sh
./main
```
## Sample Input
Input is already implemented in main.c itself. It inputs the following (airports, dvalue) in the heap and has table:
1. (GHI, 4)
2. (JKL, 7)
1. (MNO, 3)
1. (PQR, 1)
1. (STU, 10)
1. (VQX, 8)
1. (YYZ, 4)
1. (NUY, 100)
It then prints all the heap and hash elements.
Then decrease_key is called for the following airports:
1. (STU, 10) -> (STU, 2)
2. (NUY, 100) -> (NUY, 1)
Finally, it prints all the heap and hash elements again.
## Sample Output
```
Printing heap elements...
<-----START----->
0: Airport PQR has shortest distance 1
1: Airport MNO has shortest distance 3
2: Airport GHI has shortest distance 4
3: Airport JKL has shortest distance 7
4: Airport STU has shortest distance 10
5: Airport VQX has shortest distance 8
6: Airport YYZ has shortest distance 4
7: Airport NUY has shortest distance 100
<-----END------->
Printing hash elements...
<-----START----->
53: NUY is at heap index 7
439: YYZ is at heap index 6
452: GHI is at heap index 2
475: MNO is at heap index 1
560: JKL is at heap index 3
583: PQR is at heap index 0
691: STU is at heap index 4
997: VQX is at heap index 5
<-----END------->
Decreasing the dvalues of airports STU and NUY. Print the updated results.
Printing heap elements...
<-----START----->
0: Airport PQR has shortest distance 1
1: Airport NUY has shortest distance 1
2: Airport GHI has shortest distance 4
3: Airport STU has shortest distance 2
4: Airport MNO has shortest distance 3
5: Airport VQX has shortest distance 8
6: Airport YYZ has shortest distance 4
7: Airport JKL has shortest distance 7
<-----END------->
Printing hash elements...
<-----START----->
53: NUY is at heap index 1
439: YYZ is at heap index 6
452: GHI is at heap index 2
475: MNO is at heap index 4
560: JKL is at heap index 7
583: PQR is at heap index 0
691: STU is at heap index 3
997: VQX is at heap index 5
<-----END------->
```