Unformatted text preview:

This homework is necessary preparation for the lab Make sure you type your answers in files you bring to the lab so that you will not have to waste time entering your code during the lab 1 Implement the following method that given a queue and an entry of type T searches for the given entry in the given queue and if it finds it moves that entry to the front of the queue 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Finds code x in code q and if such exists moves it to the front of code q param T type of code Queue entries param q the code Queue to be searched param x the entry to be searched for updates q ensures pre perms q q and if x is substring of q then x is prefix of q pre private static T void moveToFront Queue T q T x Queue T q1 q newInstance while q length 0 T s2 q dequeue q1 enqueue s2 if s2 equals x q1 rotate 1 q transferFrom q1 Note that moveToFront is a static generic method it is parameterized by the type T of the entries in the queue You can use the type T wherever you need to declare a variable that refers to an object of type T Pay attention to the contract There is no requires clause If you have trouble reading and understanding the ensures clause be sure to ask for help 2 Develop a complete test plan for the Set constructor and kernel methods add remove removeAny contains and size and enter them in SetTest You can find some more information on how to effectively test removeAny here For the homework turn in printouts of your implementation of moveToFront and of the SetTest java file test add public final void testAdd Set String s this createFromArgsTest tiger cat Set String sExpected this createFromArgsRef dog tiget cat s add dog assertEquals s sExpected test remove how to solve this problem public final static testRemove Set String s this createFromArgsTest tiger cat Set String sExpected this createFromArgsRef dog tiget cat String remove s remove dog return remove assertEquals s sExpected test removeAny public final static testRemoveAnny Set String s this createFromArgsTest tiger cat Set String sExpected this createFromArgsRef dog tiget cat String remove s removeAny dog return remove assertEquals s sExpected I do know how to write the content and size I will come to office hours


View Full Document

OSU CSE 1223 - Homework 8

Documents in this Course
Load more
Download Homework 8
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework 8 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework 8 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?