Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have provided the framework of the class for you: class “LRULinkedCache.java”.

ID: 3602739 • Letter: I

Question

I have provided the framework of the class for you: class “LRULinkedCache.java”. This class has the following attributes: • theSize: The current number of items in the cache • capacity: The capacity of the cache (the maximum number of items which can be stored in the cache) • head: reference to the head node • Tail: reference to the tail node All you need to do is implementing three parts of this class: 1. the nested CacheNode class: This class encapsulates the building block of a cache node. It contains a key and value, as well as a reference to both the next and previous nodes in the list. K is a parametric (generic) type for the key and V is a parametric type for the value. 2. LRUGet(K key): This method returns the value for a given key in the cache and moves the node which contains the key to the end of the list (because it is most recently accessed). The method returns null if there is no node with the given key. 3. LRUPut(K key, V value): This method adds a new node with the given key and value to the end of the list. If the cache is full, the least recently used node (the first node after head) is removed to make room for new node. Since duplicate keys are not allowed, the method must first check to see if a node with a given key already exists in the cache and if so, it updates its value and move the node to the end of the list. Please follow these guidelines when implementing your class: 1. Do not extend any of the data structure classes or interfaces I provided in the “source code” (doing so will be more trouble than it is worth). You do not need to use any other file beyond the provided LRULinkedCache.java file. 2. You can add any private helper method you want; but your code will be graded based on the LRUGet and LRUPut methods. 3. The class in its current form is not compiled as its missing the implementations requested above. After you add your implementations you can compile and test your class. For example, if you use the following main method: Notice when LRUPput(1,9) is called, since a node with key=1 already exists in the cache, its value is updated to 9 and the node (1,9) is moved to the end of the list. When LRUGet(3) is called the value for key=3 is returned and the node (3,7) is moved to the end of the list. When LRUPut(5,10) is called the cache has reached its capacity, so the least recently used node (2,2) is removed from the cache and (5,10) is added to the end of the list. When LRUGet(10) is called the cache is remained unchanged as there is no node with key=10 in the cache. LRULinkedCache.java public class LRULinkedCache { /************* * attributes ************/ /** current number of items in cache */ private int theSize; /** The capacity of cache. */ private int capacity; /** reference to list header node */ private CacheNode head; /** reference to list tail node */ private CacheNode tail; /*************** * constructors **************/ /** * return a new, empty cache with a given capacity */ public LRULinkedCache(int capacity) { this.capacity=capacity; // empty this LinkedList clear(); } /********** * methods *********/ /************************************** * methods inherited from class Object *************************************/ /** * return a String representation of the LinkedList * * items are listed in order from beginning to end in comma-delimited fashion */ public String toString() { String s = ""; CacheNode current= head.next; while(current!=tail) { s+= "("+current.key +"," +current.value+")"; if (current.next!= tail) s+=","; current= current.next; } return s; } /********************************************** * methods inherited from interface Collection *********************************************/ /** * empty the LRUCache * size will be set to zero */ public void clear() { // reset header node head = new CacheNode(null,null,null ,null); // reset tail node tail = new CacheNode(null,null,head, null); head.next=tail; tail.previous=head; // reset size to 0 theSize = 0; } /** * return the number of items in the cache */ public int size() { return theSize; } /** * return true if the cache is empty */ public boolean isEmpty() { return theSize == 0; } /** * This operation returns the value for a given key in the cache. It returns null if the data is not currently in the cache. * It also moves the data that is accessed to the end of the list and inserts it before tail */ public V LRUGet(K key) { //To do: Your implementation goes here } /** * puts a new node with key and value in the cache and adds it to the end of the cache * If the cache is full, it removes the first node (The least recently used node)before adding the new node. * If a node with the given key already exists in the cache, it updates the value for the key and moves the node with the key to the * end of the cache * @param key * @param value */ public void LRUPut(K key, V value) { //To Do: Your implementation goes here } /** * nested class ListNode * * encapsulates the fundamental building block of a LRU cache node * contains a key and value, as well as references to both the next and previous nodes * in the cache *K is the type of the key and V is the type of value */ private static class CacheNode { /************* * attributes ************/ //TODO: define attributes and constructor for CacheNode } }

Explanation / Answer


#include<stdio.h>


int main()

{
  
   int i,MAX;
  
   int a[5];
  
  
  
   for(i=0;i<5;i++)
  
   {
      
       scanf("%d",a[i]);/* input 5 numbers */
  
   }  
  
   MAX=a[0];/*initialize the first number as maximum value*/
  
   for(i=0;i<5;i++)
  
   {
      
       if(a[i]>MAX)
      
       {
          
           MAX=a[i];
      
       }
  
   }
  
   printf("the maximum of 5 numbers is%d",MAX);

return 0;

}