Write a c function void selectitemstack s itemtype n that


You need some help with some stack/queue questions!

1. A programmer wishes to do parenthesis matching, but does not want to use a stack. The programmer thus decides to simply keep three variables, ParenCount, BracketCount, and BraceCount to keep track of the number of '(', '[', and '{' characters, respectively.

The idea is that when a leftparen is seen, the corresponding variable is incremented and when a rightparen is seen, the corresponding variable is decremented. The expression is said to have balanced parentheses if the three variables are all zero after the expression has been entirely read. Will this algorithm work for checking parenthesis-matching? If so, why? If not, say why not and give a counterexample.

2. Let Q be a non-empty queue and let S be an empty stack. Write C++ code to reverse the order of the items in Q.

3. Write a C++ function queue copy_queue(queue &Q) that returns a new queue containing all of the items in Q in the same order that they were found in Q. The original queue Q must end up unchanged.

4. Write a C++ function void SelectItem(stack &S, ItemType n); that finds the first occurrence of item n on stack S and moves it to the top of the stack, leaving the other stack items in their original order. You may assume that the operator == is valid for ItemType. Note that the stack may be empty or that n may not be on the stack.

5. Let S be a stack of positive integers and let x be an integer variable. Write C++ code fragments to perform each of the following operations:

1. Set x to the top element of S and leave the top element of S unchanged. If S is empty, set x to -1.

2. Set x to the third element from the top in S, provided that S contains at least three integers. If not, set x to -1. Leave S unchanged.

3. Set x to the bottom element of S (or to -1 if S is empty) and leave S unchanged.

4. Delete all occurrences of x from S, leaving the other elements of S in the same order.

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Write a c function void selectitemstack s itemtype n that
Reference No:- TGS02873563

Expected delivery within 24 Hours