What is the complexity of the following c code segment Show

What is the complexity of the following c++ code segment? (Show your work.) What will be the result if a postfix notation 2 3 6 5 - 4 + * will be evaluated? What will be the result If a postfix notation 2 3 4 6 5 + + * will be evaluated? New items enter a queue at its_ side, and items leave a queue from its each) Consider the implementation of queues by using arrays. How do you Initialize the pointers FRO FRONT =_, REAR =_ A node in linked list is declared as follows:

Solution

2. Given: 2 3 6 5 - 4 + *:
read 2: it is operand . push into stack . Stack: 2
read 3: it is operand . push into stack . Stack: 2 3
read 6: it is operand . push into stack . Stack: 2 3 6
read 5: it is operand . push into stack . Stack: 2 3 6 5
read -: it is operator . Pop 2 elements from stack and perform -.
6 - 5=> 1 . Store this result in stack.
Stack: 2 3 1
read 4: it is operand . push into stack . Stack: 2 3 1 4
read +: it is operator. Pop 2 elements from stack and perform +.
4 + 1=> 5 . Store this result in stack.
Stack: 2 3 5
read *: it is operator. Pop 2 elements from stack and perform *.
3 * 5=> 15 . Store this result in stack.
Stack: 2 15
Given expression is processed but still stack contains elements. So it is an error.

3. Given: 2 3 4 6 5 + + *
read 2: it is operand . push into stack . Stack: 2
read 3: it is operand . push into stack . Stack: 2 3
read 4: it is operand . push into stack . Stack: 2 3 4
read 6: it is operand . push into stack . Stack: 2 3 4 6
read 5: it is operand . push into stack . Stack: 2 3 4 6 5
read +: it is operator. Pop 2 elements from stack and perform +.
6 + 5=> 11 . Store this result in stack.
Stack: 2 3 4 11
read +: it is operator. Pop 2 elements from stack and perform +.
4 + 11=> 15 . Store this result in stack.
Stack: 2 3 15
read *: it is operator. Pop 2 elements from stack and perform *.
3 * 15=> 45 . Store this result in stack.
Stack: 2 45
Given expression is processed but still stack contains elements. So it is an error.


4. New items enter a queue at its back side , and items leave a queue from its front side.

5. FRONT=-1; REAR=-1;
These are initialized like this to indicate the queue is empty.

6.
for(Node * cur=head;cur!=NULL;cur=cur->next)
cout<<cur->item<<endl;

 What is the complexity of the following c++ code segment? (Show your work.) What will be the result if a postfix notation 2 3 6 5 - 4 + * will be evaluated? Wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site