Question

In: Computer Science

1.Read the Lab6-Background.pdf first.2.Start the “Stack Queue” applet.3.The purpose of this exercise is to see how...

1.Read the Lab6-Background.pdf first.2.Start the “Stack Queue” applet.3.The purpose of this exercise is to see how you could reverse a list of names. Push the three names “Alice,” “Bob,” and “Charles” onto the stack. When you pop the stack 3 times, what do you see in the text field next to “Pop”?4.Write an algorithm in pseudo-codethat would describe how to use a stack to reversea sequence (list)of letters and print them. For instance, if the original sequence is COMPUTERthe output will be RETUPMOC. Review pages 249-250 of the textbook(Chapter8)to see the related sample pseudo-codes.5.A palindrome word is one that has the same sequence of letters if you read it from right to left or left to right(e.g., radar or madam). Describe (in terms of a pseudo-code) how you could use a stack in conjunction with the original listto determine if a sequence is a palindrome.Hint:Given that the letters have been already assigned to both stackand the queueand these two data structures are ready to be processed (compared).

Solutions

Expert Solution

Since, a stack works on LIFO(Last In First Out) so when you push the three names onto the stack, the top refers to the index where "Charles" is stored. On calling Pop(), the value of last top is removed and the new top becomes "Bob". On second Pop(), the value of last top is removed and the new top becomes "Alice". After the third call for Pop(), since the stack has only one item left, it deletes the last item and the stack becomes null or empty.

SEQUENCE REVERSAL

function Reverse(Argument One)

create a new stack equal to the capacity of the string

for counter from 0 to length of string

push the character at counter index onto the stack

for counter from 0 to length of string

pop the top of stack and replace it with the character at counter position in the string

now print the string (i.e. reversed string)

CHECK FOR PALINDROME

function isPalindrome(Argument One)

  find the length of the string

calculate the variable mid by dividing length by 2

create a new stack

for counter1 from 0 to length of string

  if counter1 < mid

push the character at counter1 index onto the stack

if length%2 is not equal 0

neglect mid

if counter1 from mid to length - 1

pop the character from stack and compare with the character at counter1 index

if same then continue else return false


Related Solutions

Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack List 2. Display the list 3. Create the function isEmply 4. Count the number of nodes 5. Insert a new node in the Stack List. 6. Delete the node in the Stack List. 7. Call all methods above in main method with the following data: Test Data : Input the number of nodes : 4 Input data for node 1 : 5 Input data...
* Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2-...
* Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the application. >---=== Python Temperature Analyzer ===---<. 3- Using a for loop, prompt the user to enter the high and low values for each of NUMS days. The values entered must be between -40 and 40, and high must be greater than low. Print the following messages: > Enter the high value for day 1: < (or day 2, or...
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2,...
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2, dequeue, enqueue 3, enqueue 4, dequeue, enqueue 5. What are the resultant contents of the queue, from front to back? Group of answer choices 1, 2, 3, 4, 5 1, 3, 5 1, 2, 3 3, 4, 5 Assume you are using the text's array-based queue and have just instantiated a queue of capacity 10. You enqueue 5 elements, dequeue 4 elements, and then...
> * Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3...
> * Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the application. >---=== Python Temperature Analyzer ===---< Enter the high value for day 1: < (or day 2, or day 3) Enter the low value for day 1: < (or day 2, or day 3) 3- Using a for loop, prompt the user to enter the high and low values for each of NUMS days. The values entered must...
1.Where does TLS fit on the Internet protocol stack? 2.How do applications use TLS? 3.How does...
1.Where does TLS fit on the Internet protocol stack? 2.How do applications use TLS? 3.How does TLS provide authentication? Does it provide mutual authentication (both client and server-side)? Is that required? 4.What is the purpose of padding, Message Authentication Code (MAC), handshake protocol, change cyber suite (CCS) protocol? 5.How does TLS provide: confidentiality, availability, integrity, non-repudiation? 6.Is TCP a user of TLS services or does it provide services to TLS (hard question) – explain your answer in one sentence? 7.Does...
Use stack to evaluate postfix expressions : 5 4 2 1 + 6 * + 3...
Use stack to evaluate postfix expressions : 5 4 2 1 + 6 * + 3 + *
1. Describe the purpose of diffusion experiment. 2. Describe the purpose of osmosis experiment. 3. Describe...
1. Describe the purpose of diffusion experiment. 2. Describe the purpose of osmosis experiment. 3. Describe the observation/results of the osmosis experiment.
Read the articles 1 and 2 (see recommended reading) - NIYATI VORA and RAJ KISHORE PATRA...
Read the articles 1 and 2 (see recommended reading) - NIYATI VORA and RAJ KISHORE PATRA ( 2017): Importance of Internal Communication: Impact on Employee Engagement in Organizations - Cristina Borca and Viorica Baesu (2013). A Possible Managerial Approach for Internal Organizational - After analysing it, explain, in your proper terms, what you have understood in the topics of these articles - Write your abstract for each article in 1/2 page not more.
Please code in C /* Implements functions that operate on Stack 1. PUSH 2. POP 3....
Please code in C /* Implements functions that operate on Stack 1. PUSH 2. POP 3. isEmpty 4. PEEK 5. Size */ #include <stdio.h> #define CAPACITY 1000 //Two stacks .. for each stack we need // 1. An Array that can hold capacity of elements // 2. A top initialzied to -1 (signifying that the stak is empty at the start) //NOTE : THESE STACKS ARE OF TYPE CHAR :( ... so you need to FIX IT!!!! to int and...
1- What is the purpose of ANOVA ? 2- What are the assumptions of ANOVA? 3-...
1- What is the purpose of ANOVA ? 2- What are the assumptions of ANOVA? 3- When and how should you use multiple comparison procedures for evaluating pairwise combinations of the group means?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT