PriorityQueue

PriorityQueue - /* * Author: Dave Toth * Date: November 26,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * Author: Dave Toth * Date: November 26, 2005 * * This class is a priority queue. It uses an array to store the nodes. * */ public class PriorityQueue { p //////////////////////////////////////////////////////////////// // Variables //////////////////////////////////////////////////////////////// Node[] queueNodes; int heapSize = 0; //////////////////////////////////////////////////////////////// // Methods //////////////////////////////////////////////////////////////// /** * Constructor. Creates the priority queue. * @param numberOfNodes - The maximum number of nodes that will be stored. */ public PriorityQueue(int numberOfNodes) { System.out.println("\n\nCreated Priority Queue"); // We "waste" 1 array slot (the 0th slot) so that the locations of // nodes and their children in the array fit the pattern that // a node in position i has children at position 2*i and (2*i) + 1. queueNodes = new Node[numberOfNodes + 1]; for (int initializer = 0; initializer < numberOfNodes + 1; initializer ++) { queueNodes[initializer] = null; } } /** * Inserts the given Node into the priority queue. * @param node - The Node to insert into the queue.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/10/2009 for the course CS 2223 taught by Professor Ruiz during the Fall '05 term at WPI.

Page1 / 4

PriorityQueue - /* * Author: Dave Toth * Date: November 26,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online