• Home
  • University of the People
  • Data Structures (proctored course) CS 3303
  • Data Structures with Buffer Pool Algorithm

Data Structures with Buffer Pool Algorithm

8/7/22, 1:36 AM CS 3303-01 - AY2022-T5: Discussion Forum-Unit 7 CS 3303-01 Data Structures - AY2022-T5 Dashboard / My courses / CS 3303-01 - AY2022-T5 / 28 July - 3 August / _Discussion Forum Unit 7 /_Discussion Forum-Unit 7 0 Search forums Discussion Forum Unit 7 Discussion Forum-Unit 7 # Settings Display replies in nested form The cut-off date for posting to this forum is reached so you can no longer post to it. Discussion Forum-Unit 7 by Rupali Memane (Instructor) - Tuesday, 14 June 2022, 10:37 AM Discussion Assignment Using Jeliot, execute the following algorithm which implements a buffer pool algorithm. The algorithm offers options for three different heuristics including LRU, LFU, and FIFO. import Prog1Tools.IOTools; import java.util.* class replacepage public static void main(String args1){ boolean flag: int f, page=0, ch, pgf=0, n, chn=0, k, pt; int pages: //pgf-page fault System.out.printIn("Menu 1.FIFO 2. LRU 3. LFU"); System.out.printIn("ENTER YOUR CHOICE: "); Scanner in = new Scanner(System.in); ch = in.nextInt0; switch(ch) case 1: pt=0; System.out.printIn("enter no. of buffers (available buffers in the pool) "); f=in.nextIntO; int buffer=new int[f]; for(int i=0;i<f;i++) buffer[i]=-1; } https://my.uopeople.edu/mod/forum/discuss.php?d=808774 1/51 8/7/22, 1:36 AM CS 3303-01 - AY2022-T5: Discussion Forum-Unit 7 System.out.printIn("enter the no of pages (items to be stored): "); n=in.nextIntO; pages=new int[n]; System.out.printIn("enter the page value (an item to place in a buffer): "); for(int j=0;j<n;j++) pages[j]=in.nextInt0; }op int pg=0; for(pg=0;pg<n;pg++) page=pages[pg]; flag=true; for(int j=0;j<f;j++) if(page=buffer[j]) flag=false; break; 1 if(flag) buffer[pt]=page; pt++; if(pt==f) pt=0; System.out.print("buffer :"); for(int j=0;j<f;j++) System.out.print(buffer[j]+" "); System.out.printInO; pgf++; else System.out.print("buffer :); for(int j=0;j<f;j++) System.out.print(buffer[j]+" "); System.out.printIn0: chn++; } } while(chn!=n); break; case 2: k=0; System.out.printIn("enter no. of buffers (available buffers in the pool): "); f=in.nextInt(: int buffer1=new int[f]; int a=new int[f]; int b=new int[f]; for(int i=0;i<f;i++) buffer1[i]=-1; a[i]=-1; b[i]=-1; System.out.printIn("enter the no of pages (items to be stored): "); n=in.nextIntO; pages=new int[n]; System.out.printIn("enter the page value (an item to place in a buffer): "); https://my.uopeople.edu/mod/forum/discuss.php?d=808774 2/51 8/7/22, 1:36 AM CS 3303-01 - AY2022-T5: Discussion Forum-Unit 7 for(int j=0;j<n;j++) pages[j]=in.nextInt(; dol int pg=0; for(pg=0;pg<n;pg++) page=pages[pg]; flag=true; for(int j=0;j<f;j++) if(page==buffer1[j]) flag=false; break; { for(int j=0;j<f && flag;j++) if(buffer1[j]=a[f-1]) k=j; break; } if(flag) buffer1[k]=page; System.out.printIn("buffer :" ): for(int j=0;j<f;j++) System.out.print(buffer1[j]+" "); pgf++; System.out.printInO: else System.out.printIn("buffer :" ): for(int j=0;j<f;j++) System.out.print(buffer1[j]+" "); System.out.printIn0; int p=1; b[0]=page; for(int j=0;j<a.length;j++) if(page!=a[j] && p<f) b[p]=a[j]; p++; for(int j=0;j<f;j++) { a[j]=b[j]; } chn++; } while(chn!=n); break; https//my.uopeople.edu/mod/forum/discuss.php?d=808774 3