Question

Write python code for the queue class buuilt with a linked list using: First- returns first...

Write python code for the queue class buuilt with a linked list using: First- returns first value in queue, PrintQ-returns whole queue as list, RemoveValue-removes specific value from queue, RemoveIndex-removes value from queue by index

Homework Answers

Answer #1

Its a sample program . May be get some small run time error which you can fix while running

# Python program to

# demonstrate queue implementation

# using linked list

queue = []

# Adding elements to the queue

queue.append('m')

queue.append('n')

queue.append('o')

print("Initial queue")

print(queue)

# Removing elements from the queue

print("\nElements dequeued from queue")

print(queue.pop(0))

print(queue.pop(0))

print(queue.pop(0))

print("\nQueue after removing elements")

print(queue)

# not commenting print(queue.pop(0))

# will raise and IndexError

# as the queue is now empty

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
A Queue is a linked list with pointers to both the head of the list as...
A Queue is a linked list with pointers to both the head of the list as well as the tail (or the last element) of the list. Given a queue Q, Q.head gives the head of the queue and Q.tail gives the tail of the queue. Give O(1) time algorithms for the following tasks. Enqueue • Input: A queue Q of distinct integers and a queue element a not in Q. 1 • Output: Q with the element a added...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145' PYTHON
Given this definition of a generic Linked List node: public class LLNode {     private T...
Given this definition of a generic Linked List node: public class LLNode {     private T data;     private LLNode next;     public LLNode(T data, LLNode next) {           this.data = data;           this.next = next;     }     public void setNext(LLNode newNext){ next = newNext; }     public LLNode getNext(){ return next; }     public T getData() {return data;} } Write the findMinimumNode method body. This method returns the linked list node that contains the minimum value in the...
Write a program to swap mth and nth elements of a linked list. Code needed in...
Write a program to swap mth and nth elements of a linked list. Code needed in java.
Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has...
Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has the following methods: clear – clears the queue; is_empty – returns 1 if the queue is empty, otherwise 0; is_full – returns 1 if the queue is full, otherwise 0; add – adds a new string at the end of the queue; remove – removes the string from the front of the queue. Use ADT queue to solve the following problems: • Write an...
A) In C++ a linked list is implement as STL. i)vector ii)array iii)list iv)queue B) Which...
A) In C++ a linked list is implement as STL. i)vector ii)array iii)list iv)queue B) Which of the following characterizes a stack? i)first in, first out ii)first in, never out iii)last-in, first-out iv)last in, last out C) Which of the following characterizes a queue? i)first in, first out ii)first in, never out iii)last-in, first-out iv)last in, never out
Write a java program using java.util package to add these elements to linked list {KKU, KSU,...
Write a java program using java.util package to add these elements to linked list {KKU, KSU, KAU, NU} then add -KAUSTI to index 2 and remove the KKU element.
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT