Solution For LRU Stack
The objective is to i mplement a stack using LinkedList. You need to implement push and pop function. When push is called, insert the items in list at the head. When the stack is empty and pop is called return 0 The maximum stack size allowed is 5 Whenever a push is called Case 1 : Value is NOT present in stack: If the stack is full (has 5 items) then remove the oldest pushed item on the stack and push the new item. If the stack is not full, then push the new item Case 2 : Value is already present in stack: Since the item is already present in the stack move it to the top of the stack. Algorithm Step 1 :- Create a class(or structure ,depends on the programming language) with a data members for the creation of linked list. Step 2:- Implement push and pop function using a linked list as we do normally. Step 3:- In push function before pushing the element to stack check the size of the stack. ->if size is less than 5 ,then push the element normally. ->els...
Comments
Post a Comment