优先级队列的实现

原文地址: 优先级队列的实现

Introduction

实现数据结构中ADT的Priority Queue.

Priority Queue

Resources

You might find the following online resource useful while tackling this assignment:

  • Java 8 Online Documentation
  • JUnit 4 Getting Started Online Documentation
  • UML Diagram Online Documentation
  • Java Tutorial: Interfaces and Inheritance
  • Abstract Data Types

Maven Archetype Setup

In this assignment, we will use the course Maven archetype (the archetype from Lab 3). As a reminder, you may create the archetype by following these steps:

  1. Start IntelliJ and create a new project.
  2. In the New Project selection window, in the left-hand pane, instead of selecting Java select Maven.
  3. Once you select Maven in the left-hand pane, the right-hand pane populates with archetypes.
  4. Go to the top of the right-hand pane and check the box with the title Create from archetype.
  5. Choose built-in archetype named:

    • org.apache.maven.archetypes:maven-archetype-quickstart
  6. As soon as you click the button the Add Archetype, window appears. Enter the following information in each box in the order specified in the Maven Guide.
  7. Click button Next.
  8. On the next screen, you need to choose Maven Home Directory. Please choose the following directory:

    • /Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3
  9. Click button Next again.
  10. On the next screen, please choose name and location for your Maven project. (You may want to choose project name to be Assignment5, and location to be your local copy of your personal repo on CCIS GitHub course organization).
  11. Click Finish. This should create a new Maven project for you.
  12. Pay attention to IntelliJ's console window. You will see a lot of messages and information.

Process finished with exit code 0
This indicates that the build was Successful.

Updating the pom.xml file in your Maven project

  • You are not quite yet done setting up your new Maven project. In order to make the project use the proper external libraries, you will need to update dependencies.
  • To do so, go to your Project Explorer window, and expand the node with your IntelliJ's project name.
  • Find a document called pom.xml, and open it in IntelliJ.
  • Replace the text that is currently stored in the pom.xml file with the following text (note: this is the same text that we used in the previous assignments)
  • Save your updated pom.xml file.
  • IntelliJ has a dedicated window that allows us to manage and use Maven. On IntelliJ's main menu, go to View -> Tool Windows -> Maven Projects. This should pop-up the dedicated Maven window located in the top right corner of your IntelliJ window.
  • NOTE: when you minimize the Maven Window, IntelliJ places a vertical tab in the right margin of the IntelliJ window with the tab title Maven Projects
  • Click on the drop-down menu called CS5004 Assignment, and refresh it.
  • Then rebuild your Maven project (using the green start button).
  • When you do that, the whole Maven project should rebuild again, and it should once again finish with lines similar to.

Repository Content

Your repositories should contain only the following

  1. pom.xml file and
  2. src folder with appropriate sub-folders with your code and tests
  3. Files with your UML diagrams

Code Criteria

  • Naming convention: Your solution for each problem should be in its own package. The package names should follow this naming convention where you replace N with the assignment number, and with the problem number.
  • Maven built: Your project should successfully build using the course Maven archetype, and it should generate all the default reports.
  • Javadoc generation: Your Javadoc generation should complete with no errors or warnings.
  • Checkstyle report: Your Checkstyle report must have no violations.
  • Code coverage report: Your JaCoCo report must indicate 70% or more code coverage per package for "Branches" and "Instructions".
  • FindBugs report: Your FindBugs report must have no violations (except for violations categorized as PERFORMANCE or SECURITY, you can ignore those).
  • PMD report: Your PMD report should have no violations.

Some Additional Expectations and Restrictions

  • Testing your code: you should provide test for all of your classes and methods within them, but in this assignment, you are not expected to test interfaces.
  • Javadoc: please include a short description of your class/method, as well as tags from @params and @returns in your Javadoc documentations (code comments). Additionally, if your method throws an exception, please also include a tag @throws to indicate that.
  • UML diagrams: You may generate UML diagrams for this assignment.
  • Methods hashCode(), equals(), toString(): all of your classes have to provide appropriate implementations for methods:
  • boolean equals(Object o)
  • int hashCode()
  • String toString()

(appropriate means that it is sufficient to autogenerate these methods, as long as autogenerated methods suffice for your specific implementation). Please don't forget to autogenerate your methods in an appropriate order - starting from the ancestor classes, towards the concrete classes.

Releasing your Code for Final Submission

When you are ready to submit your homework for grading, please create a Release (you do not need to do this for any intermediate commits as you work on your assignment). Below is step-by-step guide to creating a Release:

Step 1

  • In your browser, navigate to our course organization on GitHub.
  • Open up your personal repository.

Step 2

  • Make sure that all of the code related to this assignment is placed within a folder (package) named Assignment4.

Step 3

  • Just above the list of files and folders in your repo, you will see a menu bar that says something like, "X commits 1 branch X releases X contributors"

Click on the releases link.

Step 4

  • Click on the button, Draft a new release.

Step 5

  • In the tag version field, enter the identifier for the homework, Assignment 4.
  • In the release title field, enter the current date and time. Note that GitHub makes visible the date and time that a release was created so please be honest when you create the release title. We're only asking you to enter the date and time to make the appropriate release easier for TAs to find in the list.

Step 6

  • Click Publish release.

Problem 1

Note: This problem should be solved assuming we are in an immutable Java world.
In this problem, you are asked to implement a Priority Queue (PQ), based upon a provided ADT. A priority queue is a data structure, where every element of a PQ contains two properties:

  1. A priority - typically a positive Integer
  2. A value associated with the priority - in our case the value will be a String

The PQ should have the following operations:

  1. createEmtpy() : PQ - creates an empty priority queue.
  2. add(Integer priority, String value) : PQ - adds the given value with its associated priority in PQ.
  3. peek() : String - returns the value in PQ that has the highest priority.

    • For two positive integers i, j such that i < j then i has a lower priority than j. The PQ remains unchanged. Calling peek() on an empty PQ should signal an error.
  4. pop() : PQ - returns the PQ without the element with the highest priority.

    • Calling pop() - on an empty PQ should signal an error.
  5. isEmpty() : Boolean - returns true if the PQ is empty, returns false otherwise.

Your tasks

  1. Design Java classes to capture the above requirements and information.
  2. Additionally, provide implementation for your method equals(Object o) that returns true if the two PriorityQueues have the same exact elements; exactly the same priorities and exactly the same values (if there are duplicates).
  3. Please write appropriate Javadoc documentation for all of your classes and methods.
  4. Please write the corresponding test classes for all of your classes.
  5. Please provide a final UML Class Diagram for your design.

Problem 2

Note: This problem should be solved assuming we are in an immutable Java world.

You are helping a start-up Natural Language Processing (NLP) team develop fundamental code for their Bag-of-Words Model. In the bag-of-words model, some text is represented as a multiset (a bag) of its words, where we disregard grammar and often also the order of words.

Your job is to design and implement the first version of the BagOfWords. A BagOfWords is a data container, holding Strings (words). A BagOfWords can contain duplicates, and Strings (words) have no order.

Here is a more detailed specification of your BagOfWords ADT. This specification uses the following notation:

  • [] denotes an empty BagOfWords
  • [a, b, c] denotes a BagOfWords with three Strings, a, b, c. The order of the elements does not matter, which means that BagOfWords [a, b, c], [b, c, a], [c, a, b], and [c, b, a] are all the same.
  • Notation ++ denotes the addition of an element into our BagOfWords. For example:

    • t ++ [d, e] = [d, e, t]
  • |tedBagOfWords| denotes the number of elements in tedBagOfWords.

Your tasks

  1. Design Java classes to capture the above requirements and information.
  2. Additionally, provide implementation for your method equals(Object o) that returns true if the two BagsOfWords have the same exact elements; exactly the same Strings and exactly the same number of times in the BagOfWords (if there are duplicates). Remember that the order of elements in a BagOfWords does not matter.
  3. Please write appropriate Javadoc documentation for all of your classes and methods.
  4. Please write the corresponding test classes for all of your classes.
  5. Please provide a final UML Class Diagram for your design.

(本文出自csprojectedu.com,转载请注明出处)

你可能感兴趣的:(queue)