= A | B | C + | * | () | –< | / | F. This grammar generates sentences(S) made up of nouns (N) and verbs(V). Generate two sentences that make sense and two that don’t. NOTE: NP is noun phrase and VP is verb Phrase S NP VP NP the N VP V NP V sings | eats N cat | song | canary G. Show that you have two stacks – astack filled with data and auxstack which is empty-show how you can do each of the following tasks by using only the stack operations of the stack ADT we discussed in class. Make sure you also explain the steps you are doing in the order you are doing them. Display the contents of the astack in reverse order; that is display the top last. 25 30 45 50 70 25 30 25 Astack Count the number of items in astack, leaving astack unchanged. Delete every occurrence of 25 from astack leaving the order...

To display the contents of the astack in reverse order, we can use the stack ADT operations. The stack ADT typically consists of operations like push (to add an item to the top of the stack), pop (to remove the top item from the stack), and peek (to view the top item without removing it).

To display the contents of the astack in reverse order, we can use an auxiliary stack (auxstack). Here are the steps to achieve this:

1. Initialize the auxstack as an empty stack.
2. While the astack is not empty, do the following:
a. Pop the top item from the astack.
b. Push the popped item onto the auxstack.
3. Once the astack becomes empty, we have all the items from the astack in reverse order in the auxstack.
4. Now, to display the contents of the astack in reverse order, we can pop each item from the auxstack and print it.

Here is an example to demonstrate these steps:

Initial astack: [25, 30, 45, 50, 70]

1. Initialize auxstack as an empty stack.
astack: []
auxstack: []

2. While astack is not empty:
Pop the top item from the astack and push it onto the auxstack.
astack: []
auxstack: [70, 50, 45, 30, 25]

3. The astack became empty, and the auxstack now contains all the items from astack in reverse order.

4. To display the contents of the astack in reverse order, we can pop each item from the auxstack and print it.
Printing the items: 70 50 45 30 25

So, the contents of the astack in reverse order are 70, 50, 45, 30, 25.

To count the number of items in the astack without changing its contents, we can use the size operation of the stack ADT. The size operation returns the number of items currently in the stack.

Here is an example:

Initial astack: [25, 30, 45, 50, 70]

To count the number of items in the astack, we can use the size operation:

Size of astack: 5

Therefore, the number of items in the astack is 5.

To delete every occurrence of 25 from the astack while maintaining the order of other items, we can use the pop operation to remove items from the stack and push operation to re-insert items back into the astack.

Here are the steps to achieve this:

1. Initialize an empty temporary stack (tempstack).
2. While the astack is not empty, do the following:
a. Pop the top item from the astack.
b. If the popped item is not equal to 25, push it into the tempstack.
4. Once the astack becomes empty, we have removed all occurrences of 25 while maintaining the order of other items.
5. Now, while the tempstack is not empty, do the following:
a. Pop the top item from the tempstack.
b. Push the popped item back into the astack.
6. The astack now contains all the items except 25 in the same order.

Here is an example:

Initial astack: [25, 30, 45, 50, 70, 25]
Temporary empty tempstack: []
Target item to delete: 25

Step 2:
Pop 25 from astack and push it into tempstack.
astack: [30, 45, 50, 70, 25]
tempstack: [25]

Step 2:
Pop 30 from astack and push it into tempstack.
astack: [45, 50, 70, 25]
tempstack: [25, 30]

Step 2:
Pop 45 from astack and push it into tempstack.
astack: [50, 70, 25]
tempstack: [25, 30, 45]

Step 2:
Pop 50 from astack and push it into tempstack.
astack: [70, 25]
tempstack: [25, 30, 45, 50]

Step 2:
Pop 70 from astack and push it into tempstack.
astack: [25]
tempstack: [25, 30, 45, 50, 70]

Step 2:
Pop 25 from astack and push it into tempstack.
astack: []
tempstack: [25, 30, 45, 50, 70, 25]

Step 5:
Pop 25 from tempstack and push it back into astack.
astack: [25]
tempstack: [30, 45, 50, 70, 25]

Step 5:
Pop 30 from tempstack and push it back into astack.
astack: [25, 30]
tempstack: [45, 50, 70, 25]

Step 5:
Pop 45 from tempstack and push it back into astack.
astack: [25, 30, 45]
tempstack: [50, 70, 25]

Step 5:
Pop 50 from tempstack and push it back into astack.
astack: [25, 30, 45, 50]
tempstack: [70, 25]

Step 5:
Pop 70 from tempstack and push it back into astack.
astack: [25, 30, 45, 50, 70]
tempstack: [25]

Step 5:
Pop 25 from tempstack and push it back into astack.
astack: [25, 30, 45, 50, 70, 25]
tempstack: []

Now, the astack contains all the items except 25 in the same order:

Final astack: [25, 30, 45, 50, 70]

Therefore, every occurrence of 25 has been deleted from the astack, leaving the order of other items unchanged.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer