We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>
Share Your Solutions!
Share This With Friends......+ Click Here To Join also Our facebook study Group. This Content Originally Published by a member of VU Students.
Please Discuss here about this assignment.Thanks
Our main purpose here discussion not just Solution
We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions. Read More>>
Discussed & be touched with this discussion. After discussion a perfect solution will come in a result at the end.
P.S: Please always try to add the discussion in proper format title like “CS101 Assignment / GDB No 01 Solution & Discussion Due Date: ___________”
Share below link with friends for solution & Discussion. A Single link for help in your education.
Cs301 2nd assignment solution Spring 2019
You are required to write a program in C++ to implement Stack data structure and use this data structure to evaluate Postfix expression. You have to implement Stack data structure using doubly linked list. A stack is a LIFO structure in which data elements are stored in an order such that last element pushed on the stack will be popped up first.
The Stack data structure will be implemented in such way so that Nodes will be added and removed at the end of link list. In this case, head node will point to most recent element. After popping elements from Stack, head will move to previous Node.
After implementing Stack data structure, you will now use this data structure to evaluate postfix expression.
Implementation of Stack using linked memory (Doubly linked list):
You will implement Stack using class. The Stack class will have following member functions:
This method will push data elements on Stack. So, the head node will point to the top of stack.
This method will remove elements from Stack. This will display the value and then will delete the node from Stack. After deleting node, the head will move to previous Node in the stack.
This method will retrieve the value of top Node of the stack without deleting the node.
This method will check if the Stack is empty or not.
The Stack class will have data members and constructor which you will define accordingly.
The Stack class will use Node class to add, remove and retrieve nodes in the stack.
You can see from the below pictures, when a new node is pushed on the stack, the head node moves forward and points to most recent Node.
As the head is pointing to most recent element containing data element 8, so after pop() operation, the node will be removed from the stack and head will point to previous node containing value 6as shown below:
Note: As the head node will now point to previous node so in that case, information regarding address of previous node may be needed. So, make sure to implement Stack by keeping in mind the address of previous nodes like in the case of doubly linked list.
After another pop() operation, the node will be removed from the stack and head will point to previous node containing value 2 as shown below:
Evaluating Postfix expression:
After implementing Stack data structure, you can now evaluate postfix expression by using stack.
You will define a evaluatePostfix() method which will take a postfix expression. This method will display the length of expressionand a value after evaluating this expression.
Detail of main() method:
In main() method, user will declare three postfix expressions and then will pass these expressions to evaluatePostfix()method which will display the length of postfix expressions and then display the value after evaluating this expression.
The first expression should be43+5* and its evaluated value will be 35.
The second expression should be 435*+ and its evaluated value will be 19.
The third expression should be623+-382/+*2^3+and its evaluated value will be 52.
Sample screenshots of program:
cs301 assignment no.2 solution