Question: I really need some assistance! I've created a program for a list based stack, but I continue to receive error message Stack has no attribute

I really need some assistance! I've created a program for a list based stack, but I continue to receive error message "Stack" has no attribute "list". If anyone could guide me in the right direction, that would be great!
Design and implement an experiment that will compare the performance of the Python list-based stack and queue with the linked list implementation. Provide a brief discussion of both stacks and queues for this activity.
#implementating a stack with linked list
import gc
gc.collect()
class Node:
def initial(self,new_data):
self.data = new_data
self.next = None
class Stack:
#set head as null by default
def initial(self):
self.head = None
# Checks if stack is empty
def isempty(self):
if self.head == None:
return True
else:
return False
#adding data to the stack
def push(self,new_data):
if self.head == None:
self.head = Node(new_data)
else:
new_node = Node(new_data)
new_node.next = self.head
self.head = new_node
#removes current head from the stack
def pop(self):
if self.isempty:
return None
else:
pop_item = self.list.head.data
self.list.remove_head(None)
return pop_item
num_stack = Stack()
num_stack.push(40)
num_stack.push(74)
num_stack.push(25)
num_stack.push(37)
print("Element stack after push is:", end='')
listedNode = num_stack.list.head
while listedNode != None:
print(listedNode.data, end='')
listedNode = listedNode.next
print()
pop_item = num_stack.pop()
print("Popped element:", pop_item)
print("Elements stack after pop is:", end='')
listedNode = num_stack.list.head
while listedNode != None:
print(listedNode.data, end='')
listedNode = listedNode.next
print('
')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!