SHARE
TWEET

sdadsadadasdasdasdasdsadasdsa

shortguyy Oct 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Chp. 30 Lab 3  
  2. // Lab 3 involves manipulating a queue data structure
  3.  
  4. // no data structures may be used except for stacks and queues
  5.  
  6. // Queue methods that you are allowed to use are listed below:
  7. // public boolean add (E x),  public E remove(),  public E peek(),  public boolean isEmpty()
  8.          
  9. // Stack methods that you are allowed to use are listed below:
  10. // public boolean push (E x),  public E pop(),  public E peek(),  public boolean isEmpty()
  11.  
  12.  
  13. import java.util.*;
  14.  
  15. public class Chp30Lab3
  16. {
  17.     public static void main(String args[])
  18.     {
  19.         System.out.println("Java3016.java\n\n");
  20.         QueueManipulate <Integer> ourQueue = new QueueManipulate <Integer> ();
  21.        
  22.            
  23.         QueueManipulate <Integer> theirQueue = new QueueManipulate <Integer> (ourQueue);
  24.        
  25.     //  etc...
  26.        
  27.        
  28.         System.out.println("\n\n");
  29.     }
  30. }
  31.    
  32. class QueueManipulate<E>
  33. {
  34.    
  35.     private Queue <E> myQueue;
  36.      
  37.     // default constructor - instantiates myQueue, myQueue should be empty after this constructor call
  38.     public QueueManipulate()
  39.     {
  40.         myQueue = new <E> LinkedList();
  41.     }
  42.    
  43.    
  44.    
  45.     // overloaded constructor - recieves parameter queue(a queue of type E), instantiates myQueue, and
  46.     // copies all data items from parameter queue(front to back) into myQueue(front to back)
  47.     public QueueManipulate(Queue <E> queue)
  48.     {
  49.         myQueue = new <E> LinkedList();
  50.         E holder;
  51.         E holder2;
  52.         while(queue.isEmpty())
  53.         {
  54.             holder = queue.remove();
  55.             holder2 = holder;
  56.             queue.add(holder);
  57.             myQueue.add(holder2);
  58.         }
  59.     }
  60.      
  61.    
  62.    
  63.     // copy constructor - recieves parameter queueManipObj(a QueueManipulate object), instantiates myQueue(of the curent oject in scope), and
  64.     // copies all data items from myQueue(of parameter queueManipObj, front to back) into myQueue(of the curent oject in scope, front to back)  
  65.     // all data items in myQueue(of the parameter queueManipObj) should not be affected and remain in the same order
  66.     public QueueManipulate(QueueManipulate queueManipObj)
  67.     {
  68.        
  69.     }
  70.    
  71.    
  72.    
  73.     // displays all data items in myQueue, front to back (each item on a seperate line) while preserving the order of data items in myQueue
  74.     public void display()  
  75.     {
  76.          
  77.     }
  78.    
  79.    
  80.    
  81.     // receives parameter target(of type E), removes the first occurrence of target from myQueue and leaves the remaining data items in myQueue intact 
  82.     // returns true if target found, returns false if target not found
  83.     public boolean removeFirst(E target)
  84.     {
  85.         return true;
  86.     }
  87.    
  88.    
  89.    
  90.     // receives parameter target(of type E), removes all occurrences of target from myQueue and leaves the remaining data items in myQueue intact  
  91.     // returns true if target(s) found, returns false if target(s) not found
  92.     public boolean removeAll(E target)
  93.     {
  94.         return true;
  95.     }
  96.    
  97.    
  98.    
  99.     // reverses the the data items in myQueue (ie.  1 2 3 4   shold now be   4 3 2 1)  
  100.     public void reverse()
  101.     {
  102.    
  103.     }
  104.    
  105.        
  106.        
  107.     // recieves parameter queueManipObj(a QueueManipulate object), copies all data items from myQueue(of the curent oject in scope, front to back)
  108.     // into myQueue(of parameter queueManipObj, front to back)
  109.     // this is a clone method not an append method  ***  myQueue of parameter queueManipObj should be empty before you copy data items
  110.     // all data items in myQueue(of the curent oject in scope) should not be affected and remain in the same order
  111.     public void clone(QueueManipulate queueManipObj)
  112.     {
  113.    
  114.     }
  115.    
  116.    
  117.    
  118.     // recieves parameter queueManipObj(a QueueManipulate object), copies all data items from myQueue(of parameter queueManipObj, front to back)
  119.     // to the back of myQueue(of the curent oject in scope)
  120.     // this is an append method not a copy constructor or clone method  ***  do not remove any data items in myQueue of (of the curent oject in scope)  
  121.     // all data items in myQueue(of the parameter queueManipObj) should not be affected and remain in the same order
  122.     public void append(QueueManipulate queueManipObj)
  123.     {
  124.    
  125.     }
  126.    
  127.    
  128.    
  129.     // receives parameters target and newValue(both of type E), replaces ALL occurrences of target, contained in myQueue, with parameter newValue
  130.     // all other data items in myQueue should not be affected and remain in the same order
  131.     // return the amount of data items that were replaced
  132.     public int replace(E target, E newValue )
  133.     {
  134.        
  135.         return -999;
  136.     }
  137.    
  138.    
  139.    
  140.     // receives parameter target(of type E), searches myQueue for target, if target is found, return true and,
  141.     // move ALL occurrences of target to the front of myQueue (there may be one, more than one, or no occurrence of target)
  142.     // if target not found return false
  143.     // all other data items in myQueue should not be affected and remain in the same order         
  144.     public boolean moveToFront(E target)
  145.     {        
  146.        
  147.         return true;  
  148.     }
  149.        
  150.        
  151.        
  152.     // receives parameter target(of type E), searches myQueue for target, if target is found, return true and,
  153.     // move ALL occurrences of target to the back of myQueue (there may be one, more than one, or no occurrence of target)
  154.     // if target not found return false
  155.     // all other data items in myQueue should not be affected and remain in the same order         
  156.     public boolean moveToBack(E target)
  157.     {        
  158.        
  159.         return true;  
  160.     }  
  161.        
  162.          
  163.        
  164.     // receives parameters target and newValue(both of type E), searches myQueue for target, if target is found, return true and                                               
  165.     // insert the parameter newValue immediately BEFORE ALL occurrences of target(there may be one, more than one, or no occurrence of target)
  166.     // if target not found return false
  167.     // all other data items in myQueue should not be affected and remain in the same order         
  168.     public boolean insertItem(E target, E newValue)
  169.     {
  170.        
  171.         return true;  
  172.     }  
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top