Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LRU(char nodes[], int noNodes, int pages) {
- char holder[pages];
- int curr = 0;
- int order[pages];
- initialize(holder, order, pages);
- for (int i = 0; i <= noNodes; i++)
- {
- int temp = inMem(holder, nodes[i]);
- if (temp >= 0)
- {
- order[(curr%pages)] = temp;
- curr++;
- }
- else
- {
- int temp2 = ifFree(holder);
- if (temp2 != -1)
- {
- holder[temp2] = nodes[i];
- cout << "Page Fault at time = " << i << " swapped in candidate " << nodes[i] << endl;
- order[temp2] = temp2;
- }
- else
- {
- int temp3 = 0;
- if (curr%pages != pages)
- temp3 = curr%pages;
- cout << "Page Fault at time = " << i << " swapped in candidate " << nodes[i] << " into "
- << temp3 << ": " << holder[temp3] << endl;
- holder[temp3] = nodes[i];
- order[(curr%pages)] = temp3;
- curr++;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment