Question

In: Computer Science

Python: Solve following problems using Linked List Data Structure 2. Create a Queue class. In the...

Python:

Solve following problems using Linked List Data Structure

2. Create a Queue class. In the queue class create enqueue, dequeue, first, empty, len and resize methods. The class should support circular queue and have the ability to resize the queue.

Solutions

Expert Solution

ANS:

# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.

class Node:
def __init__(self):
self.item=None
self.linked=None
class CQueue:
def __init__(self):
front=None
rear=None

#This is enqueue which will make circular queue

def Enqueue(q,value):
temp=Node()
temp.item=value
  
if(q.front==None):
q.front=temp
else:
q.rear.linked=temp
  
q.rear=temp
q.rear.linked=q.front


#deleting element from Circular queue

def Dequeue(q):
if(q.front==None):
print("Queue Empty!")
return -1000
value=None
if(q.front==q.rear):
  
value=q.front.item
q.front=None
q.rear=None
else:
temp=q.front
value=temp.item
q.front=q.front.linked
q.rear.linked=q.front
  
return value
  
def first(q):
return q.front

def display(q):
temp=q.front
print("Circular Queue Elements:")
  
while(temp.linked!=q.front):
print(temp.item, end=" ")
temp=temp.linked
print(temp.item)
  
if __name__ == '__main__':
q = CQueue()
q.front = q.rear = None

Enqueue(q, 20)
Enqueue(q, 18)
Enqueue(q, 9)
Enqueue(q,12)
  
#print("First=",first(q))
  
  
display(q)
  
print("Deleted value = ", Dequeue(q))
print("Deleted value = ", Dequeue(q))
  

display(q)
  
Enqueue(q, 100)
Enqueue(q, 80)
display(q)


COMMENT DOWN FOR ANY QUERIES!!!
HIT A THUMBS UP IF YOU DO LIKE IT!!!


Related Solutions

Write a code to implement a python queue class using a linked list. use these operations...
Write a code to implement a python queue class using a linked list. use these operations isEmpty • enqueue. • dequeue    • size Time and compare the performances of the operations ( this is optional but I would appreciate it)
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue...
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue will call on a linkedlist class class Queue: def __init__(self): self.items = LinkedList() #has to be O(1) def enqueue(self, item): #has to be O(1) def dequeue(self): def is_empty(self): def __len__(self):
Objectives: Define the new class type: Queue using a singly linked list. Define the new class...
Objectives: Define the new class type: Queue using a singly linked list. Define the new class type: Jukebox which creates three objects of type Queue class. Practice enqueue-ing and dequeue-ing elements from the top of your singly linked list Queue class. Test the implementation of the class: MyTunes. The class files are here: https://drive.google.com/file/d/1yCCQeZCS-uLoL_CK0Et9dX-KCaokXQxR/view?usp=sharing class MyTunes Creates an object of type MyTunes class that partially simulate the digital jukebox TouchTunes, using a queue which holds playlist. Tests the implementation of...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
JAVA DATA STRUCTURE (Linked Lists/Queue) public class Node {    int value;    Node nextNode;   ...
JAVA DATA STRUCTURE (Linked Lists/Queue) public class Node {    int value;    Node nextNode;    Node(int v, Node n){        value = v;        nextNode = n;    }    Node (int v){        this(v,null);    } } public class Stack {    protected Node top;    Stack(){        top = null;    }    boolean isEmpty(){        return( top == null);    }    void push(int v){        Node tempPointer;       ...
In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
Solve this Write a C++ class that implements a stack using a linked list. The type...
Solve this Write a C++ class that implements a stack using a linked list. The type of data contained in the stack should be double. The maximum size of the stack is 30. Implement the following methods: . · Constructor and destructor; // 5 pts · void push (double value); // pushes an element with the value into the stack. 5 pts. · double pop (); // pops an element from the stack and returns its value. 5 pts. ·...
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
10.5 LAB: Air-traffic control (queue using a linked list) Given a partial main() and PlaneQueue class,...
10.5 LAB: Air-traffic control (queue using a linked list) Given a partial main() and PlaneQueue class, write the push() and pop() methods for PlaneQueue. Then complete the main() to read in whether flights are arriving or have landed at an airport. An "arriving" flight is pushed onto the queue. A "landed" flight is popped from the front of the queue. Output the queue after each plane is pushed or popped. Entering -1 exits the program. Ex: If the input is:...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT