2D Array and Insertion Sort
2D Array and Insertion Sort
Make sure that your name, centre number and candidate number will appear on every page of this
document. This document must contain your answers to each question.
If the programming language does not support arrays, a list can be used
Characters.txt
1 A computer program is needed to store jobs in order of priority. Each job has a job number (for
example, 123) and a priority from 1 to 10, with 1 being the highest priority and 10 the lowest.
For example:
The global variable, NumberOfJobs, stores the number of jobs currently in the array.
(a) Write program code to declare the global 2D array Jobs and the global variable
NumberOfJobs.
Copy and paste the program code into part 1(a) in the evidence document.
[3]
(b) The procedure Initialise() stores –1 in each of the array elements and assigns 0 to
NumberOfJobs.
Copy and paste the program code into part 1(c) in the evidence document.
[5]
(d) The main program should call the procedure Initialise() and then use the AddJob()
procedure to store the following jobs in the order given:
Job number Priority
12 10
526 9
33 8
12 9
78 1
Write program code for the main program and perform the tasks described. Save
your program.
Copy and paste the program code into part 1(d) in the evidence document.
[2]
(e) When a new job has been added, the array is sorted into ascending numerical order of priority
using an insertion sort.
Write program code for the procedure InsertionSort() to sort the data into ascending numerical
order of priority.
Save your program.
Copy and paste the program code into part 1(e) in the evidence document.
[5]
4
(f) The procedure PrintArray() outputs each job number and priority on a line, for example:
123 priority 1
39 priority 3
120 priority 7
Copy and paste the program code into part 1(f) in the evidence document.
[3] (g) The main program needs to sort the array and then output the contents of the array.
(i) Amend the main program by writing program code to call procedures InsertionSort() and
PrintArray().
Copy and paste the program code into part 1(g)(i) in the evidence document. [1]
Copy and paste the screenshot into part 1(g)(ii) in the evidence document.
[1]