Question

Write the pseudocode for an algorithm called copystack that copies the contents of one stack into...

Write the pseudocode for an algorithm called copystack that copies the contents of one stack into another. The algorithm passes two stacks, the source stack and the destination stack. The order of the stacks must be identical.

Note: please number the steps, Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pseudo Code:

1. Create a temporary stack

2. Repeat steps 3 and 4 unless source stack is empty

3. Push top of source stack to the temporary stack.

4. Pop the source stack.

5. Repeat steps 6 and 7 unless temporary stack is empty

6. Push top of temporary stack to the destination stack.

7. Pop the temporary stack.

8. Now, Destination stack is having all the elements of source stack in same order.

Add a comment
Know the answer?
Add Answer to:
Write the pseudocode for an algorithm called copystack that copies the contents of one stack into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program which is called ‘multiple_copy’. This program copies one source file to two...

    Write a C program which is called ‘multiple_copy’. This program copies one source file to two destination files as follows: $./multiple_copy....... source_file....... destination_file1......... destination_file2 multiple_copy program copies the contents of source file (i.e., source_file) to any named two destination files in the command line. The number of arguments should be 4 including multiple_copy. If the number of arguments is not 4, the program should display error message saying: “Usage: multiple_copy source_file destination_file1 destination_file2”. When the source_file does not exist, the...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • Write a program that uses a stack to reverse its inputs. Your stack must be generic...

    Write a program that uses a stack to reverse its inputs. Your stack must be generic and you must demonstrate that it accepts both String and Integer types. Your stack must implement the following methods: push, pop, isEmpty (returns true if the stack is empty and false otherwise), and size (returns an integer value for the number of items in the stack). You may use either an ArrayList or a LinkedList to implement your stack. Also, your pop method must...

  • Given a single linked chain of nodes with positive integers, write an algorithm in pseudocode to...

    Given a single linked chain of nodes with positive integers, write an algorithm in pseudocode to rearrange the nodes in one pass in such a way that all integers that are odd appear at the end. The relative order of the elements does not need to remain the same. List all the steps in the proper order that are necessary to rearrange the nodes, show how the next pointers are being changed. Each data element should “stay” in its original...

  • Please Write Pseudocode or Python code! Thanks! P1. b) is the following: W1. (6 marks) Write...

    Please Write Pseudocode or Python code! Thanks! P1. b) is the following: W1. (6 marks) Write the pseudocode for removing and returning only the second element from the Stack. The top element of the Stack will remain the top element after this operation. You may assume that the Stack contains at least two items before this operation. (a) Write the algorithm as a provider implementing a Stack using a contiguous memory implementation. You can refer to the implementation given in...

  • Subject: Algorithm need this urgent please thank you. 4. Give pseudocode for an algorithm that will solve the following problem. Given an array A[1..n) that contains every number between 1 and n +...

    Subject: Algorithm need this urgent please thank you. 4. Give pseudocode for an algorithm that will solve the following problem. Given an array A[1..n) that contains every number between 1 and n +1 in order, except that one of the numbers is missing. Find the miss sorted ing mber. Your algorithm should run in time (log n). (Hint: Modify Binary search). A pseudocode means an algorithm with if statements and loops, etc. Don't just write a paragraph. Also, if your...

  • Need in pseudocode Program 2: POWIN3D. In the early 80s, hackers used to write in an...

    Need in pseudocode Program 2: POWIN3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called "leet" - short for "elite". In essence, it was a simple character replacement algorithm, whereya single "regular" character was replaced by one or more "leet" characters; numbers remained the same. Here's one of the most readable versions: g9m AS$y 00u | |р | P v II 9 IQ W LrRXI>< VI Note! You will need to know how...

  • List the names of subroutines of the hierarchy chart, and then write complete pseudocode for the...

    List the names of subroutines of the hierarchy chart, and then write complete pseudocode for the following problem. You will not have to create a data dictionary for this exercise. Problem: A sporting goods store ships a lot of baseballs. They only have one size shipping-box. Twenty-four baseballs will fill a shipping-box. Produce the pseudocode logic for an algorithm that will compute the number of shipping-boxes required for the number of baseballs to be shipped. The information is given as...

  • Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The...

    Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...

  • Write a C++ program that will determine if one input string is a subsequence of a...

    Write a C++ program that will determine if one input string is a subsequence of a second input string. In a subsequence, all the characters in the first string will also be in the second string in the same order. For example: “abc” is a subsequence of “qzabc”. While the characters must be in the same order, they do not have to be consecutive. For example: “abc” is also a subsequence of “aaqbzcw”. We will use two stacks one and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT