Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. void LRU(char nodes[], int noNodes, int pages) {
  2. char holder[pages];
  3. int curr = 0;
  4. int order[pages];
  5. initialize(holder, order, pages);
  6. for (int i = 0; i <= noNodes; i++)
  7. {
  8.  
  9. int temp = inMem(holder, nodes[i]);
  10. if (temp >= 0)
  11. {
  12. order[(curr%pages)] = temp;
  13. curr++;
  14. }
  15. else
  16. {
  17. int temp2 = ifFree(holder);
  18. if (temp2 != -1)
  19. {
  20. holder[temp2] = nodes[i];
  21. cout << "Page Fault at time = " << i << " swapped in candidate " << nodes[i] << endl;
  22. order[temp2] = temp2;
  23. }
  24. else
  25. {
  26. int temp3 = 0;
  27. if (curr%pages != pages)
  28. temp3 = curr%pages;
  29. cout << "Page Fault at time = " << i << " swapped in candidate " << nodes[i] << " into "
  30. << temp3 << ": " << holder[temp3] << endl;
  31. holder[temp3] = nodes[i];
  32. order[(curr%pages)] = temp3;
  33. curr++;
  34. }
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment