



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A system problem for a unified computers & programming course in spring 2006. Students are required to modify and add sections to existing code for a priority queue. What a priority queue is, provides information on the files to be modified, and offers hints for implementation. The goal is to parse/read a file for information, store it in a priority queue, and dynamically draw the pointer manipulations.
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!
Page 2 of 6
This System Problem is a departure from the C&P work you have done in the past. While you are typically asked to create the programs, this one will ask you to modify and add sections to existing code. For this SPL you will be pulling together many of the C&P lessons. Your program will parse/read a file for information, store this information in a priority queue, and then dynamically draw how the pointers are being manipulated in the queue to make this all possible. The final result should be similar to “test_queue.exe”.
First, what is a priority queue? As you should know, a queue is a method of dynamically storing information using pointers. By definition, a queue is supposed to be FIFO (First In, First Out). A priority queue is a little different. You give the element a value when it is Enqueued. Upon Dequeue, the element in the queue with the smallest or largest associated value is returned. Our priority queue will return the element with minimum associated value current in the queue.
In the two files you are expected to modify: “priority_queue.adb” and “test_queue.adb” you will find comments “--Fill in here as needed.” These are locations that may need code. Since one of the skills tested in this SPL is code reuse, read the comments in the given code or associated .ads file! You will find that most of the .adb files are poorly commented, while the .ads files are richly commented. This is typical of most programming languages, the specification file or header file is has more explanations.
The procedures in “priority_queue.adb” that require modification are:
A few words on “priority_queue.adb” The record types that will form the nodes/elements of the queue have already been defined and can be found in “priority_queue.ads. ” The general structure of the priority queue is depicted in Figure 1. The Queue Type holds the basic information you need to know about the Queue, the size and where its Head and Tail are. The Nodes form the backbone of the Queue. Each Node has a pointer linking it to the next Node (which should have a greater Value). Each Node also has a data Element which gives the (X, Y) coordinates at which each Node should be drawn in the window. The Tail pointer points to the last Node in the Queue, which has no pointer to any other Node.
ToDo: ! Modify these procedures so that they act as described in “priority_queue.ads”. (Hint: Look at the “Linked_List” package on the Unified C&P Website Extra Material, Lecture C5 for implementation ideas).
Professor Kristina I. Lundqvist
Page 3 of 6
! Interleave into your code, procedures that graphically draw (and erase) the pointers as they are being manipulated. Look at the helper functions in “priority_queue” and graphical functions in “priority_queue_graphics” to make drawing much easier. Sections of your code that have been modified to have graphics will typically look like: EraseSomething(…);-- This is the added graphics Pointer1 := Pointer2 –- This is the important part DrawSomething(…); -- This is the added graphics
Figure 1: Structure of Priority Queue. Nodes should be linked from one to the Next starting with the minimum Value first.
The procedures in “test_queue.adb” that require modification are:
Head Tail Size : Integer
Queue
Value : Float Element Next
Node
X : Integer Y : Integer
Element
Value : Float Element Next = Null
Node
X : Integer Y : Integer
Element
Value : Float Element Next
Node
X : Integer Y : Integer
Element
Professor Kristina I. Lundqvist
Page 5 of 6
Green Pointer – Pointer to the Head of the Queue Yellow Pointer – Pointer to the Tail of the Queue Orange Pointer – Pointer to the Newly Created Node/Element Red Pointer – Pointer using for sorting Purple Pointer – Pointer used for sorting Blue Circles – Graphical representation of a Node/Element of the Queue Green Links – The pointer from one Element to the Next in the Queue. Note that every time a pointer is given a new value, the old pointer is erased and the new one drawn. (The .exe has been known to not display correctly on some machines)
Professor Kristina I. Lundqvist
Page 6 of 6
10 - Complete Window Creation in “Test_Priority_Queue.” 10 - File Parsing in “Test_Priority_Queue” and “Draw_Queue.” 10 - Correct pointer manipulation in “MakeEmpty” procedure 25 - Correct pointer manipulation in “Enqueue” procedure 15 - Correct pointer manipulation in “Dequeue” procedure 5 - Working Graphics for “MakeEmpty” 10 - Working Graphics for “Enqueue” 5 - Working Graphics for “Dequeue” 10 – Paragraph or Pseudo Code on how the pointers are manipulated by Enqueue and how your graphics window relates (what are all the colorful pointers doing)?
assignment via the on-line submission system (At least make sure “priority_queue.adb” and “test_queue.adb” are included).
Reminder: ! READ THE COMMENTS! ! “Linked_List.ads” and “Test_Ada_Graphics.adb” are good resources. ! Remember to check for a null pointer before using it