RU beehive logo ITEC dept promo banner
ITEC 320
2018fall
nokie
ibarland

Pointers and ADTs
freeing memory in Ada; implementing queue hints

See Dr Okie's notes on

Here is the code for linked-list put,equal we discussed/developed in class.

Hints on Implementing a Queue

In class, we reviewed code for a singly-linked-list (which can implement a stack easily). But queues are a bit more involved1. In class I sketched a special header struct which keeps track of the front and end of our singly-linked-list, as follows (though in lecture I fumbled which field should be called "front" and which "rear"):

diagram of a linked-list implementation of a queue

incremental steps

The following steps are suggested, good incremental steps to your hw. (Don't try to write everything, and only then start to compile/run/test!) And: be sure to draw pictures — if you don't have lots of scribbles of memory diagrams, you're doing it wrong! (The final exam will have questions that require understanding what pointers to update in what order, w/o access to a textbook/internet.)

  1. Starting:
  2. enqueue:
  3. dequeue:
  4. dequeue:
  5. Generic types: Add a type-parameter to your package, to generalize it from queue-of-Integer. This might entail moving your test-list-involving-integers to outside the package, or (as in code for linked-list put,equal) pass in particular integers.

Freeing memory


1 Assuming we want O(1) enqueue, using singly-linked lists.      
2 Of course, dequeueing when there are zero items should throw an exception.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.