
I'm getting a different output. I need to get the expected output
Python Code:
from Stack import Stack
def display_(S_):
node = S_.list.head
while node != None:
print(node.data)
node = node.next
def Sorting_Stack(num_stack):
temp_head1 = num_stack.list.head
# sorting the strings in the stack in descending order using bubble sort
while(temp_head1!=None):
temp_head2 = temp_head1.next
# looping through to end and placing the greatest element at the current position
while(temp_head2!=None):
# if next element of the current is greater then swapping
if(temp_head2.data>temp_head1.data):
temp_d = temp_head1.data
temp_head1.data = temp_head2.data
temp_head2.data = temp_d
temp_head2 = temp_head2.next
temp_head1 = temp_head1.next
if __name__ == '__main__':
# creatin stack
str_stack = Stack()
# taking user input till sentinel value is entered
inp_str = input()
while (inp_str != "End"):
str_stack.push(inp_str)
inp_str = input()
if (str_stack.list.head == None):
print("Empty Stack, enter a valid string!")
inp_str = input()
str_stack.push(inp_str)
# sorting and displaying the sorted stack
Sorting_Stack(str_stack)
display_(str_stack)


Step by stepSolved in 4 steps with 2 images

Need to fix code to pass the final output in image
Python code:
from Stack import Stack
def display_(S_):
node = S_.list.head
while node != None:
print(node.data)
node = node.next
def Sorting_Stack(num_stack):
temp_head1 = num_stack.list.head
# sorting the strings in the stack in descending order using bubble sort
while(temp_head1!=None):
temp_head2 = temp_head1.next
# looping through to end and placing the greatest element at the current position
while(temp_head2!=None):
# if next element of the current is greater then swapping
if(temp_head2.data>temp_head1.data):
temp_d = temp_head1.data
temp_head1.data = temp_head2.data
temp_head2.data = temp_d
temp_head2 = temp_head2.next
temp_head1 = temp_head1.next
if __name__ == '__main__':
# creatin stack
str_stack = Stack()
# taking user input till sentinel value is entered
inp_str = input()
while (inp_str != "End"):
str_stack.push(inp_str)
inp_str = input()
if (str_stack.list.head == None):
print("Empty Stack, enter a valid string!")
inp_str = input()
str_stack.push(inp_str)
# sorting and displaying the sorted stack
Sorting_Stack(str_stack)
display_(str_stack)

Need to fix code to pass the final output in image
Python code:
from Stack import Stack
def display_(S_):
node = S_.list.head
while node != None:
print(node.data)
node = node.next
def Sorting_Stack(num_stack):
temp_head1 = num_stack.list.head
# sorting the strings in the stack in descending order using bubble sort
while(temp_head1!=None):
temp_head2 = temp_head1.next
# looping through to end and placing the greatest element at the current position
while(temp_head2!=None):
# if next element of the current is greater then swapping
if(temp_head2.data>temp_head1.data):
temp_d = temp_head1.data
temp_head1.data = temp_head2.data
temp_head2.data = temp_d
temp_head2 = temp_head2.next
temp_head1 = temp_head1.next
if __name__ == '__main__':
# creatin stack
str_stack = Stack()
# taking user input till sentinel value is entered
inp_str = input()
while (inp_str != "End"):
str_stack.push(inp_str)
inp_str = input()
if (str_stack.list.head == None):
print("Empty Stack, enter a valid string!")
inp_str = input()
str_stack.push(inp_str)
# sorting and displaying the sorted stack
Sorting_Stack(str_stack)
display_(str_stack)

- Parallel Lists JumpinJive.py >- Terminal Summary 1 # JumpinJava.py - This program looks up and prints t and prices of coffee orders. 2 # Input: In this lab, you use what you have learned about parallel lists to complete a partially completed Interactive Python program. 3 # Output: Name and price of coffee orders or error if add-in is not found 4 The program should either print the name and price for a coffee add-in from the Jumpin' Jive 5 # Declare variables. Coffee Shop or it should print the message "Sorry, we do not carry that.". 6 NUM_ITEMS = 5 # Named constant 8 # Initialized list of add-ins 9 addIns = ["Cream", "Cinnamon", "Chocolate", "Amarett "Whiskey"] Read the problem description carefully before you begin. The data file provided for this lab includes the necessary input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints 10 the error message if the add-in is not…arrow_forwardAn important step in programming a stack is to decide on the operations. O True O Falsearrow_forwardWhat are the operations that can be performed on a stack?arrow_forward
- Need help with python code. Write a LikedStack . Test it by: Add numbers from 7 to 22 in the stack. Print the length of the stack Check if the stack is empty Show the item on the top of the stack Remove the last item in the stack Add 45 to the stack Remove all items in the stack Check if the stack is empty """File: linkedstack.pyAuthor: Ken Lambert"""from node import Nodefrom abstractstack import AbstractStackclass LinkedStack(AbstractStack):"""A link-based stack implementation."""# Constructordef __init__(self, sourceCollection = None):"""Sets the initial state of self, which includes thecontents of sourceCollection, if it's present."""# Accessor methodsdef __iter__(self):"""Supports iteration over a view of self.Visits items from bottom to top of stack."""def visitNodes(node):"""Adds items to tempList from tail to head."""def peek(self):"""Returns the item at the top of the stack.Precondition: the stack is not empty.Raises: KeyError if the stack is empty."""if self.isEmpty():#…arrow_forwardMachine organization The following operations are performed on a stack: PUSH A, PUSH B, POP, PUSH C, POP,POP,PUSH D, PUSH E, POP, PUSH F. What does the stack contain after each operation?arrow_forwardPYTHON PROGRAMMING ONLY PLZ( USING STACKS AND QUEUES)(DO NOT JUST PRINT THE RAW LIST MUST BE IN A STACK) my code and an example of a stack will be below just need help a little confused. Write a small program that simulates a doctor's Office. Your office will perform the following tasks Keep track of the waiting list using a queue Keep track of what checks need to happen to each person in a stack (check temperature, check weight, etc..). Your program will Ask the patient for their name. (you will store this data in a queue) (You must have at least 4 names in your queue before calling them to the doctor) Ask the customers what brings them in today Display to the console You will show your patients being called to the doctor and the queue changing. Describe your queue do not just print the raw list You will show the doctor administering the checks in the stack and your stack being updated. Describe your stack do not just print the raw stack How you create the doctor's…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





