In Python 2) Design and implement a method for the stack class -discussed in class- that outputs -prints- the items in the stack from bottom to top with the condition that after the execution of this method the content of the stack is equal to the content of the stack before the method was called. You may assume that the items in the stack are printable. You cannot use any variables of any aggregate data types such as lists or sets or dictionaries etc.
Let the given stack be A. The approach would be to create another stack B, pop all elements in A and push them into B. Now pop and print each element in B and put them back in A. This would preserve the state of A.
---------------------------------------------
Please find the code below :
stackA = []
stackA.append(1)
stackA.append(2)
stackA.append(3)
stackA.append(4)
stackA.append(5)
print('Initial state of stackA: ')
print(stackA)
stackB = []
stackB.append(stackA.pop())
stackB.append(stackA.pop())
stackB.append(stackA.pop())
stackB.append(stackA.pop())
stackB.append(stackA.pop())
print('Printing elements of stackA in bottom up manner')
while len(stackB) > 0:
temp = stackB.pop()
print(temp)
stackA.append(temp)
print('Final state of stackA: ')
print(stackA)
----------------------------------------

In Python 2) Design and implement a method for the stack class -discussed in class- that...
Implement the Point class (code for this up to the isHigher
method was discussed in the
lecture). The class has the following instance variables:
• x coordinate (an int)
• y coordinate (an int)
and the following methods:
• Constructor that sets the x and y coordinates
• Get and set methods
• Method equals if this point is equal to another point object
(if the x and y coordinates are the
same).
• Method isHigher if this point is...
•PYTHON!!!!!!!!!!! Design Stack class using composition, but this time, use the beginning of the list as the reference to push or pop items.
PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...
SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...
11.2 Problem Set 2: PostScript Stack Commands (in python please) For this assignment you are to implement a PostScript command interpreter using a Stack. You must implement the stack using a singly-linked list. Solutions that use a data structure other than a singly-linked list will received no credit. The interpreter must read and execute a string of PostScript commands based on the following definitions: 1. = objn objn-1 … obj1 = : objn-1 … obj1 This command removes the topmost...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
template <class T> class Stack { public: /** clear * Method to clear out or empty any items on stack, * put stack back to empty state. * Postcondition: Stack is empty. */ virtual void clear() = 0; /** isEmpty * Function to determine whether the stack is empty. Needed * because it is undefined to pop from empty stack. This * function will not change the state of the stack (const). * * @returns bool true if stack is...
I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array. //Array implementation of stacks. import java.util.Arrays; public class ArrayStack implements Stack { //Declare a class constant called DEFAULT_STACK_SIZE with the value 10. private static final int DEFAULT_STACK_SIZE = 10; /* Declare two instance variables: 1. An integer called...
PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to 1. 3. A private variable of type boolean named on to represent the...
5. Stack (12 pts) Build a Stack class for a st The Stack should operat and methods also listed below ack of doubles that is compatible with the driver code below e in a LIFO (last in, first out) fashion and implement the variables a. Data Members: Declare the data item(s) you will need to manage a stack of doubles. Method Members: public void push (double input): This should add the double input to your stack public double pop ():...