首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导CSE310语言程序、讲解C++设计编程、c/c++程序调试 辅导Database|辅导Database
项目预算:
开发周期:
发布时间:
要求地区:
CSE310 Project 2: Min-Heap
In your second programming project, you will expand your first project. As in the case of
the first programming project, it should be implemented in C++, on a Linux platform such as
general.asu.edu. Your program will be graded on Gradescope, which uses a Linux platform. You
will continue to have modular design, provide a Makefile to compile various modules to generate
the executable file named run. Among other things, you need to have
1. a main program, which coordinates all other modules;
2. a module that provides utility services including command line interpretation;
3. a module that implements the min-heap data structure (all heap functions);
4. a Makefile which compiles all modules and link them into the executable.
For each module other than the main program, you should have a header file which specifies
the data structures and the prototypes of the functions in the module, and an implementation
file which implements all of the functions specified in the header file. All programs will be
compiled and graded on Gradescope. If your program works well on general.asu.edu, there
should not be much problems. You will need to submit it electronically on Gradescope via the link
on Canvas. Test cases are posted on Canvas. If your program does not compile and work on
Gradescope, you will receive 0 on this project.
You need to define the following data types.
• ELEMENT is a struct that contains a field named key, which is of type int.
• HEAP is a data type that contains three fields named capacity (of type int), size (of type
int), and H (of type **ELEMENT). H will be pointing to an array of capacity + 1 of pointers
of type *ELEMENT. Note that the size of HEAP should be equal to 12, regardless of the capacity
or the size of the heap. In other words, sizeof(HEAP) should always return 12.
The functions that you are required to implement are:
• Initialize(value) which creates an object of type HEAP with capacity equal to value, size
equal to 0, and H points to a dynamically allocated array of value+1 pointers. It then returns
a pointer to this object. This function requires you to perform dynamic memory allocation,
given the demand value. Note that you have already done this in your first project.
• PrintHeap(heap) which prints out the information of the heap pointed to by heap, including
capacity, size, and the key fields of the elements in the array with index going from 1 to
size. Note that you have already done this in your first project.
• WriteHeap(heap) which opens the file named ”HEAPoutput.txt” in write mode and write the
the information of the heap pointed to by heap to the file. The format of ”HEAPoutput.txt”
should be identical to that of ”HEAPinput.txt”.
1
• Insert(heap, element) which inserts an object of type ELEMENT pointed to by element into
the heap pointed to by heap.
• ExtractMin(heap) which deletes the minimum element from the heap pointed to by heap.
• DecreaseKey(heap, index, value) which decreases the key of heap->H[index] to value.
• min-Heapify(heap, index) which performs the heapify function at index of the array pointed
to by heap->H.
You are free to include additional parameters as you see fit and decide the return types of the
functions. You should implement a module that takes the following commands from stdin and
feeds to the main program:
• S
• P
• W
• C value
• R flag
• I value
• D flag
• K index value
The main program should react to each of the above commands in the following way.
S: On reading S, the program
1. Stops.
P: On reading P, the program does the following:
1. If heap is NULL, writes the following line to stdout:
Error: cannot print
and waits for the next command from stdin.
2. Writes the information of the heap pointed to by heap to stdout. Refer to the posted
test cases for output format.
3. Waits for the next command from stdin.
W: On reading W, the program does the following:
1. Opens the file ”HEAPout.txt” in write mode. If the file is not opened successfully, or
heap is NULL, writes the following line to stdout:
2
Error: cannot write
and waits for the next command from stdin.
2. Writes the information of the heap pointed to by heap to the file ”HEAPoutput.txt”.
”HEAPoutput.txt” should have exactly the same format as ”HEAPinput.txt”.
3. Waits for the next command from stdin.
C: On reading C value, the program does the following:
1. Calls a function in the heap module to create a heap with capacity equal to value and
size equal to 0, and return a pointer to this heap object to the caller.
2. Waits for the next command from stdin.
R: On reading R flag, the program does the following:
1. Opens the file ”HEAPinput.txt” in read mode. If the file is not opened successfully,
writes the following line to stdout:
Error: cannot open file for reading
and waits for the next command from stdin.
2. Reads in the first integer, n, from the file opened.
If heap is NULL or heap->capacity is smaller than n, writes the following line to stdout:
Error: heap overflow
and waits for the next command from stdin.
3. Reads in the next n integers key1, key2, . . ., keyn from the file, dynamically allocates
memory for an ELEMENT, sets it key to keyj
, and let heap->H[j] points to this ELEMENT,
for j = 1, 2, . . . , n.
4. Calls the BuildHeap within the heap module to build a min heap on the array H using
the linear time buildheap algorithm. Note that you have to change the algorithm
accordingly to build a min-heap, not a max-heap.
5. If flag is equal to 1, your program should write to stdout the number of min-Heapify
functions called by this BuildHeap call. Refer to the test cases for the output format.
6. Waits for the next command from stdin.
D: On reading D flag, the program does the following:
1. If heap is NULL or heap->size is 0, writes the following line to stdout:
Error: heap is NULL or empty
and waits for the next command from stdin.
2. Deletes the minimum element from the heap and writes to stdout the key of the deleted
element. Refer to the test cases for output format.
3
3. If flag is equal to 1, your program should write to stdout the number of min-Heapify
functions triggered by this delete-min operation. Refer to the test cases for the output
format.
4. Waits for the next command from stdin.
I: On reading I value, the program does the following:
1. If heap is NULL or heap->size is equal to heap->capacity, writes the following line to
stdout:
Error: heap is NULL or full
and waits for the next command from stdin.
2. Dynamically allocates memory for an ELEMENT, sets its key field to value, and inserts it
to the heap pointed to by heap.
3. Waits for the next command from stdin.
K: On reading K index value, the program does the following:
1. If heap is NULL or index is not within the interval [1, heap->size], or value is greater
than or equal to heap->H[index]->key, writes the following line to stdout:
Error: invalid call to DecreaseKey
and waits for the next command from stdin.
2. Perform the corresponding decrease key operation: decrease the key of heap->H[index]
to value by calling the DecreaseKey function in the heap module.
3. Waits for the next command from stdin.
The file HEAPinput.txt is a text file. The first line of the file contains an integer n, which
indicates the number of array elements. The next n lines contain n integers, one integer per line.
These integers are the key values of the n array elements, from the first element to the nth element.
Refer to the posted test cases for the exact format of ”HEAPinput.txt”.
Grading policies: (Sample test cases are posted on Canvas.) All programs will be graded on
Gradescope. If your program does not compile and execute on Gradescope, you will receive 0 for
this project. So start working today, and do not claim “my program works perfectly on my PC,
but I do not know how to use Gradescope.”
(0 pt) You should provide a Makefile that can be used to compile your project on Gradescope. The
executable file should be named run. If your program does not pass this step, you will receive
0 on this project.
(60 pts) You will earn 5 points for each of the 12 posted test cases your program passes on Gradescope.
(20 pts) You will earn 5 points for each of the 4 unposted test cases your program passes on Gradescope.
You should try to make your program as robust as possible. A basic principle is that your
program can complain about bad input, but should not crash.
4
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!