read in an infix expression from the console, translate it into postfix form,and then evaluate the postfix expression.RequirementsComplete the PostFixExpression class that is partially defined below.public class PostFixExpression {private List<object> L;public PostFixExpression (string s) { … }private void Analyzer (string s) { … }private void Convert ( ) { … }public float? Evaluate ( ) { … }public override string ToString( ) { … }}1. The constructor creates but does not initialize a List L of objects. It then calls private methodsAnalyzer and Convert to perform the initialization of L. 2. The method Analyzer processes the given string character by character, separates out its integerand operator components, and inserts them into list L. If a character is not a digit or an operator,then an ArgumentException is thrown with an appropriate message. 3. The method Convert transforms list L into a postfix expression usinga. a local instance of an operator (character) stack andb. the rules of precedence given earlier.No error checking is performed except for balanced parentheses. If parentheses are not balanced,then an ArgumentException is thrown with an appropriate message.Page 3 of 64. The method Evaluate returns the result of the current postfix expression using a local instance ofan operand (floating point) stack. If the postfix expression is syntactically incorrect, then the erroris identified, and null is returned. Syntax errors include:a. Too few or too many operandsb. Too few or too many operatorsA syntax error throws an ArgumentException with an appropriate message. A runtime check fordivision by 0 also throws an ArgumentException with an appropriate message. 5. The method ToString returns the string representation of the postfix expression. The main program is straightforward. It reads in a string s from the console and then declares, definesand evaluates an instance of PostFixExpression based on string s. The main program also catches anyexceptions that are raised elsewhere.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
read in an infix expression from the console, translate it into postfix form,
and then evaluate the postfix expression.
Requirements
Complete the PostFixExpression class that is partially defined below.
public class PostFixExpression {
private List<object> L;
public PostFixExpression (string s) { … }
private void Analyzer (string s) { … }
private void Convert ( ) { … }
public float? Evaluate ( ) { … }
public override string ToString( ) { … }
}
1. The constructor creates but does not initialize a List L of objects. It then calls private methods
Analyzer and Convert to perform the initialization of L.
2. The method Analyzer processes the given string character by character, separates out its integer
and operator components, and inserts them into list L. If a character is not a digit or an operator,
then an ArgumentException is thrown with an appropriate message.
3. The method Convert transforms list L into a postfix expression using
a. a local instance of an operator (character) stack and
b. the rules of precedence given earlier.
No error checking is performed except for balanced parentheses. If parentheses are not balanced,
then an ArgumentException is thrown with an appropriate message.
Page 3 of 6
4. The method Evaluate returns the result of the current postfix expression using a local instance of
an operand (floating point) stack. If the postfix expression is syntactically incorrect, then the error
is identified, and null is returned. Syntax errors include:
a. Too few or too many operands
b. Too few or too many operators
A syntax error throws an ArgumentException with an appropriate message. A runtime check for
division by 0 also throws an ArgumentException with an appropriate message.
5. The method ToString returns the string representation of the postfix expression.
The main program is straightforward. It reads in a string s from the console and then declares, defines
and evaluates an instance of PostFixExpression based on string s. The main program also catches any
exceptions that are raised elsewhere.
Step by step
Solved in 2 steps with 1 images