Posts

Showing posts from January, 2019

Program for Page Replacement Algorithms (LRU)

// LRU.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "pch.h" #include <iostream> #include <unordered_map> #include <unordered_set> using namespace std; int pageFaults(int pages[], int n, int capacity) { unordered_set<int> s; unordered_map<int, int> indexes; // Start from initial page int page_faults = 0; for (int i = 0; i < n; i++) { // Check if the set can hold more pages if (s.size() < capacity) { // Insert it into set if not present // already which represents page fault if (s.find(pages[i]) == s.end()) { s.insert(pages[i]); // increment page fault page_faults++; } // Store the recently used index of // each page indexes[pages[i]] = i; } // If the set is full then need to perform lru // i.e. remove the least recently used page // and insert the current page else { // Che

STACK IMPLEMENTATION USING LINKLIST

// stack_implemention_using_linked_list.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdlib.h> #include <iostream> using namespace std ; struct stack { int data ; struct stack *next ; }; struct stack *top = NULL; struct stack *ptop= NULL; struct stack *last= NULL; class stack_List { protected : struct stack * node; stack_List *stack_obj; /*stack_List() { node = NULL; }*/ /*~stack_List() { delete stack_obj; }*/ public : void push(int data); void pop (); void printData(); }; void stack_List::push(int data) { struct stack *temp  = NULL; temp = new (nothrow) stack ; // notthorw if memroy not availble in heap area then it won't throe badallocation insated of it will return null if(temp == NULL) { cout << "Memory Allocation Fialed"; } if(top == NULL ) { temp->data = data; temp->next = NULL; top = temp; ptop =

how to find the smallest and 2nd smallest number in an array

#include <iostream> using namespace std; int min(int arr[], int size,  int &secound_min) { int min = arr[0]; int sec_min = arr[1]; for (auto i = 0; i < size; i++) { if (arr[i] < min) { sec_min = min; min = arr[i]; } } secound_min = sec_min; return min; } int main() { int arr[10] = {5,9,2,1,10,0,-1,-2,0,3}; int secound_min; int min_vaue = min(arr,10, secound_min); cout << min_vaue << endl << secound_min << endl; }

How to Install GoogleTest Frame Work On Linux(Ubuntu) PC .

Step 1: open  Terminal (ctrl+alt+t) and type sudo apt-get install libgtest-dev (wait for few seconds) if you have already camke in your pc then below command is not required else you can use below command to install cmake : sudo apt-get install cmake step 2 : go to below directory cd /usr/src/gtest step 3 : run the below commands : sudo cmake CMakeLists.txt sudo make step   4 :  sudo cp *.a /usr/lib