Preview

Java Program on Lru(Least Recently Used)

Good Essays
Open Document
Open Document
303 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java Program on Lru(Least Recently Used)
import java.util.*; class LRU
{
static int nof,nop,i,index,m,frames[]=new int[100],fs[]=new int [100],n,miss=0,hit=0,l=0,flag1,flag2;

public static void main(String args[])
{
Scanner s=new Scanner(System.in); System.out.println("Enter the number of frames : "); nof=s.nextInt(); for(i=0;i<nof;i++) { frames[i]=-1; fs[i]=0; }

System.out.println("Enter the number of pages : "); nop=s.nextInt();; int pages[]=new int[10]; System.out.println("Enter the pages : "); for(i=0;i<nop;i++) { pages[i]=s.nextInt();; } while(l<nop) { flag1=0;flag2=0; for(int k=0;k<nof;k++) { if(pages[l]==frames[k]) { hit++; flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i<nof;i++) { if(frames[i]==-1) { frames[i]=pages[l]; miss++; flag2=1; break; } } } if(flag2==0) { for(i=0;i<nof;i++) fs[i]=0; for(m=l-1,n=1;n<nof;n++,m--) { for(i=0;i<nof;i++) { if(frames[i]==pages[m]) fs[i]=1; } } for(i=0;i<nof;i++) { if(fs[i]==0) index=i; } frames[index]=pages[l]; miss++; } l=l+1; display(); }
}

static void display()
{
for(i=0;i<nof;i++) { System.out.println("\n"+frames[i]); } System.out.println("\nMiss : "+miss+"\n\n\n");
}

}
/* OUTPUT
D:\SECMPN 60>javac LRU.java
D:\SECMPN 60>java LRU
Enter the number of frames :
3
Enter the number of pages :
7
Enter the pages :
1
2
4
1
3
5
6
1
-1
-1
Miss : 1
1
2
-1
Miss : 2
1
2
4
Miss : 3
1
2
4
Miss : 3
1
3
4
Miss : 4
1
3
5
Miss : 5
6
3
5
Miss :

You May Also Find These Documents Helpful

  • Powerful Essays

    CODE FOR THE ABOVE FRAGMENT addi $t6, $zero, 101 # the loop termination value add $t0, $zero, $zero # i = 0 addi $t2, $a0, 0 # ptr to current A[i] addi $t3, $a1, 0 # ptr to current B[i] loop: lw $t4, 0($t3) # load B[i] add $t4, $t4, $s0 # B[i] + c sw $t4, 0($t2) # store in A[i] addi $t0, $t0, 1 # i++ addi $t2, $t2, 4 # ptr to next A[i] addi $t3, $t3, 4 # ptr to next B[i] bne $t0, $t6, loop # if i < 101, goto loop IF ANY QUERIES REGARDING CODE…

    • 107 Words
    • 1 Page
    Powerful Essays
  • Good Essays

    Unit 59 Assignment 3

    • 645 Words
    • 3 Pages

    Using the code idea from task 3, this one uses an interrupt to further improve and optimise the code so it can as efficient as possible.…

    • 645 Words
    • 3 Pages
    Good Essays
  • Better Essays

    printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); ttl_wt += stfor->wt; ttl_tt += stfor->tt; temp = np = stfor; del_node(np,1) ; ++i; } else { stfor->bt -= qt; stfor->tt = temp->tt + qt; printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); np = temp = stfor; del_node(np,2); ins_node(temp); } }while(stfor !=…

    • 401 Words
    • 2 Pages
    Better Essays
  • Satisfactory Essays

    One of the activity and experience that Jerrel Muse Jr has been part of that promote healthy behavioral practices is in high school football team and made it. He also still enjoy playing soccer but is starting really love football.…

    • 200 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Wk5 Lab Joseph Laguerre

    • 287 Words
    • 4 Pages

    Write a program that draws a series of eight concentric circles. The circles should be separated by 10 pixels. Use the drawArc method.…

    • 287 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    I have been staff on a variety of servers ranging from player bases at the lowest of 2 active members, to large networks totaling 2,000 players on SOTW. Here is a list of some of the best server I have been staff on.…

    • 856 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Abstract: The aim of this experiment was to find out how accurate astrology is in predicting behaviour and traits in humans. To find this out, we carried out a survey to 17 participants. The survey included a list of statements, and the participants had to rate how relevant each statement was to them. After conducting the survey, it was found that 2 participants said the statements were very accurate, 2 said it was neither, 1 said it was fairly inaccurate, 3 said it was very inaccurate, and 22 said it was fairly accurate, being the most common answer.. The statements given to each star sign were all the same, and were general statements so they related to most of the students’ lives.…

    • 679 Words
    • 3 Pages
    Good Essays
  • Good Essays

    * Able to separate the real privacy and security risks from things you don’t have to worry about…

    • 889 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Piglatin

    • 349 Words
    • 2 Pages

    import java.io. *; / ** * Translates a sentence into pig latin. */ public class PigLatinTranslator { /** To use for input. */ private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in))…

    • 349 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Program Note

    • 1198 Words
    • 5 Pages

    S. Bach's music career became more serious when he was appointed Kapellmeister at the royal court in Kothen and later in Leipzig, Germany, where he was contracted to compose music for services every week. However, Bach was better known as a keyboard player than a composer during his life time. When he was not writing music for services at the court, he wrote secular music for instruments. Among his comparably large oeuvre, Bach wrote several suites for keyboard (namely for organ and harpsichord during that period of time.) The most well known are sets of six suites complied in the collections of French Suite, English Suite, and Partitas. The name “English” bares no stylistic reference or indication to the music. It became known as English Suite due to the subtitle “Fait pour les Anglois” (written for the English) found on a manuscript copy made by Bach’s son. During the early 18th century, the dance suites are more or less standardized as a sequence of four dance movements of different nationality, Allemande, Courante, Galop Sarabande, and Gigue, with optional dances such as Bourrée, Gavotte, or Minuet inserted between Sarabande and Gigue. The English Suite makes its distinction from the French by the inclusion of an opening prelude that was more commonly seen in an orchestra…

    • 1198 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    Connectivity to the Internet is a vital technological requirement. It’s arguably one of the best and most transformative technological advancements of our species. However, approximately 4.3 billion people who still live in rural and remote regions where telecommunication is scarce or absent are not gifted with a connection to the World Wide Web. These are mainly due to terrestrial hurdles like dense forests, deserts, mountains, etc. These restrict construction of cell towers, radio antennas and other connectivity based infrastructure. This is a problem, isn’t it?…

    • 1230 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Java Exam

    • 5195 Words
    • 21 Pages

    Java is a general-purpose, concurrent, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. Java is, as of 2012, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.…

    • 5195 Words
    • 21 Pages
    Powerful Essays
  • Good Essays

    System.out.println("Welcome to Airline Services. We Provide best flights and deals from Delhi and Mumbai to many cities Domestic as well as International");…

    • 5155 Words
    • 21 Pages
    Good Essays
  • Satisfactory Essays

    Program- set (finite) of instructions properly sequenced that can be executed by the computer will lead to the desired output…

    • 847 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    System Programming

    • 30057 Words
    • 121 Pages

    (SIC) - Machine architecture - Data and instruction formats - addressing modes instruction sets - I/O and programming.…

    • 30057 Words
    • 121 Pages
    Powerful Essays