Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago