Question
#python 1. how to implement a stack with a linked list? (method: Stack() creates a new stack that is empty. It needs no parameters and
#python
1. how to implement a stack with a linked list?
(method:
-
Stack() creates a new stack that is empty. It needs no parameters and returns an empty stack.
-
push(item) adds a new item to the top of the stack. It needs the item and returns nothing.
-
pop() removes the top item from the stack. It needs no parameters and returns the item. The stack is modified.
-
peek() returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified.
-
isEmpty() tests to see whether the stack is empty. It needs no parameters and returns a boolean value.
-
size() returns the number of items on the stack. It needs no parameters and returns an integer.
-
convert() convert this linked list into ordinary python list and print.)
2. how to implement a queue with a linked list?
(method:
-
Queue() creates a new queue that is empty. It needs no parameters and returns an empty queue.
-
enqueue(item) adds a new item to the rear of the queue. It needs the item and returns nothing.
-
dequeue() removes the front item from the queue. It needs no parameters and returns the item. The queue is modified.
-
isEmpty() tests to see whether the queue is empty. It needs no parameters and returns a boolean value.
-
size() returns the number of items in the queue. It needs no parameters and returns an integer.
-
convert() convert this linked list into ordinary python list and print.)
*default class Node?
class Node: def __init__(self,initdata): self.data = initdata self.next = None def getData(self): return self.data def getNext(self): return self.next def setData(self,newdata): self.data = newdata def setNext(self,newnext): self.next = newnext
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started