[Solved] Exercise 1 Implementing a Heap

$25

File Name: Exercise_1__Implementing_a_Heap.zip
File Size: 292.02 KB

SKU: [Solved] Exercise 1 – Implementing a Heap Category: Tag:
5/5 - (1 vote)

Due by the end of your Week2 laboratory class. (2 marks)

This exercise is to be done during your week 3 laboratory class. When you complete the exercise show your work to your lab tutor to have your work marked. The marking is based mainly on correct implementation and code readability. You should implement your code in one file (e.g. ex2.cpp, ex2.c, ex2.java). Make sure your program has a header comment block containing the name of the exercise, your name and your student login (e.g. jfk01). You may implement your solution in C, C++, java or Python.

For this exercise you are to implement a heap, using an array as shown in the lectures. The heap will be built by repeatedly:

  1. Reading an input from a file (in this case an integer)
  2. Adding it after the last element of the current heap
  3. Shifting it up into the correct position.

At the end of all the inputs you are to print out the first five elements of the heap array. Your heap should be able to hold 100 integers. A pseudocode outline for the program is given below:

Begin main

display a prompt for the file name

read in the file name try to open the file if the file fails to open

print an error message on the screen and exit fi

while we can read an int from the file insert the int into the array elihw

makeheap()

close the file for i = 1 to 5

print the ith element of the heap rof End main

Do not implement the heap using a class or with STL. The heap must be implemented using a fixed size array of ints (500 entries should be enough). The heap array and the index to the last item in the heap should be global variables.

Information on the above functions is available from moodle and the week 2 lecture notes.

When you are finished, test your program using the provided text file named Ex2.txt and show your code and the output to your lab tutor to receive your mark. Also, submit your file via unix (banshee) using the submit command below.

$ submit -u login -c CSCI203 a ex2 filename

where login is your UNIX login ID and filename is the name of your file.

.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Exercise 1 Implementing a Heap
$25