Home Previous Next

CSC205::Lecture Note::Week 09
Assignments | Code | Handouts | Resources | Email Thurman | Tweets::@compufoo
GDT::Bits:: Time  |  Weather  |  Populations  |  Special Dates

Overview Assignment(s):  [program] #Q [due 4/2/2017]

Code CircularArrayQ.java | FootNotes.java (footnotes.in.txt) | SinglyLinkedList.java | TestLinkList.java [new version] SinglyLinkedList.java | DoublyLinkedList.java


Queues

A  queue  is a data structure in which all access is restricted to the least-recently-inserted elements (FIFO: First-In-First-Out).

Operations are:

Examples of a queue: buffered input and a line printer spooler.

Another queue example: message queues.

{TopOfPage} {Oracle.com::API Specification | Tutorial} {Derek Banas Videos}


Priority Queues

A  priority queue  allows the highest priority element to be removed from a queue even though it may not be the "oldest."

Real world example of a priority queue: You go to a restaurant with a friend that has a wait. There are a number of queues: a queue for two person table, a queue for a four person table, and a queue for large party table. You are placed on the queue for a two person table. There are three "elements" ahead of you. In comes a VIP with a friend. The next two person table that opens up is given to the VIP.

An operating system may use a priority queue when scheduling jobs. By default, each job is given the same priority. CPU access is granted using a queue (first come, first served). In certain cases, however, you may have a job that needs to get more CPU usage. In those cases, it will be given a priority higher than the default. The OS will use a scheduling algorithm to ensure the higher priority job gets the CPU with more frequency.

{TopOfPage} {Oracle.com::API Specification | Tutorial} {Derek Banas Videos}


Linked Lists

A linked list is a low-level structure upon which high-level data structures can be built (e.g. stacks and queues can be implemented using a linked-list).

To date, we have grouped program data using the following ADTs (Abstract Data Types, or User Defined Types): array, class), Vector, set, list, stack, and queue (and priority queue).

Sometimes the only ADT available for organizing data is the built-in array; however, this can be problem if the the elements of the array need to be stored in some sort of order and elements are going to be inserted and deleted from the array. In these cases a linked-list may be the solution.

A linked-list is a collection of records, called nodes, each containing at least one field (member) that gives the location of the next node in the list. In the simplest case, each node contains two members: a data member (the data value of the list item) and a link member (a value locating the next node).

If each node contains only one link member, then we have a singly linked list.

Unlike an array, the nodes of a linked-list do not necessarily occupy consecutive memory locations. [C/C++ comment]

The implementation of a linked-list relies heavily on dynamic memory allocation. [Every node is dynamically allocated. When a linked-list is created, its length (i.e. # of nodes) is unknown.] [C/C++ comment]

Although arrays support "simple" list storage applications, they cannot efficiently handle dynamic changes such as inserting and deleting from the middle of a list. As we have seen, these operations require shifting elements either to the right or the left. With large volumes of data, these copy operations can be expensive.

Terminology

A linked list consists of a set of nodes. Each node contains data and link members. The first element is called the front and is pointed to by head. The end-of-list (EOL) is called the rear its link data member has the value NULL (i.e. 0). In some implementations the rear is pointed to by tail. List applications traverse the linked list using a cursor as a reference (or pointer) to the current element.

Description of a Node

A node can be described as follows:

Data
Operations

{TopOfPage} {Oracle.com::API Specification | Tutorial} {Derek Banas Videos}


Home Previous Next