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

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 Databases Questions!