Question

In: Computer Science

Linked List-Based Queue Sketches In this section you will sketch several linked list-based queues. Hint: Recall...

Linked List-Based Queue Sketches

In this section you will sketch several linked list-based queues. Hint: Recall that a proper sketch of a linked list-based queue is just a series of boxes with elements inside.

2, 3, 4

Sketch the linked list-based queue that results from the following operations:

  1. Default constructor (create empty)

  2. Add(2)

  3. Add(3)

  4. Add(4)

? Replace this with your sketch

Add and Remove

Sketch the linked list-based queue that results from the following operations:

  1. Default constructor (create empty)

  2. Add(2)

  3. Add(3)

  4. Add(4)

  5. Remove()

? Replace this with your sketch


Solutions

Expert Solution

Preliminaries :

As we are implementing LinkedList Queue. It Follows FIrst IN FIrst Out which says that which node comes earlier will leave earlier. So the newly created nodes always create at linkedlist ending and the remove will always follow remove at beginning.

The LinkedList Node is represented as below,

< value of the node >

< next address pointed by the current node >


Sketch the linked list-based queue that results from the following operations:

  1. Default constructor (create empty)
  2. Add(2)
  3. Add(3)
  4. Add(4)

Solution :

Explanation :

Step 1 : Default constructor ( create empty)

In the step one, the empty node is created and its marked as header. NULL is shown as \0. and NULL says empty value. Whenever a new node is created always have the pointing address as NULL.


Step 2 : Add(2)

Adding first node replaces the NULL value with value 2. The address is assumed to be 100. Now the Head pointer points to the address 100.


Step 3: Add(3)

Up on adding value 3 lets say the address of this node is 102. Whenever a new node is created always have the pointing address as NULL. This node is pointed by the last created node here it is head node. Now the head node pointing addres is changed as 102. ( address of the new node with value 3)

Step 4: Add(4)

Up on adding value 3 lets say the address of this node is 102. Whenever a new node is created always have the pointing address as NULL. This node is pointed by the last created node starting from the head node it traverses till the \0 { which says pointing to none } appears. Now the head node pointing addres is changed as 102. ( address of the new node with value 3).



Add and Remove

Sketch the linked list-based queue that results from the following operations:

  1. Default constructor (create empty)
  2. Add(2)
  3. Add(3)
  4. Add(4)
  5. Remove()

Solution:



Step 1 : Default constructor ( create empty)

In the step one, the empty node is created and its marked as header. NULL is shown as \0. and NULL says empty value. Whenever a new node is created always have the pointing address as NULL.

Step 2 : Add(2)

Adding first node replaces the NULL value with value 2. The address is assumed to be 100. Now the Head pointer points to the address 100.

Step 3: Add(3)

Up on adding value 3 lets say the address of this node is 102. Whenever a new node is created always have the pointing address as NULL. This node is pointed by the last created node here it is head node. Now the head node pointing addres is changed as 102. ( address of the new node with value 3)

Step 4: Add(4)

Up on adding value 3 lets say the address of this node is 102. Whenever a new node is created always have the pointing address as NULL. This node is pointed by the last created node starting from the head node it traverses till the \0 { which says pointing to none } appears. Now the head node pointing addres is changed as 102. ( address of the new node with value 3).

Step 5 : Remove

As we are implementing the LinkedList Queue. The Queue always follows FIFO ( First IN First Out). So the header node is deleted and the address node pointed by the header node becomes the new header.


Related Solutions

by java Implement a linked list generic queue. Remember queues are first in first out (FIFO)....
by java Implement a linked list generic queue. Remember queues are first in first out (FIFO). Use the driver to then test each of the methods. Simply download it and place it with the other source files. Create a class GenLLQueue which has the following: Internal class ListNode which contains: Instance variable data of type T Instance variable link of type ListNode Default constructor that sets both instance variables to null Instance Variables head which is of type ListNode which...
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
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...
write a java program to Implement a Priority Queue using a linked list. Include a main...
write a java program to Implement a Priority Queue using a linked list. Include a main method demonstrating enqueuing and dequeuing several numbers, printing the list contents for each.
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)
// priorityList.java // a priority queue based on a sorted list // to run this program:...
// priorityList.java // a priority queue based on a sorted list // to run this program: C>java PiorityQApp //////////////////////////////////////////////////////////////// class Link { public long dData; // data item public Link next; // next link in list // ------------------------------------------------------------- public Link(long dd) // constructor { dData = dd; } // ------------------------------------------------------------- public void displayLink() // display this link { System.out.print(dData + " "); } } // end class Link //////////////////////////////////////////////////////////////// class SortedList { private Link first; // ref to first item...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue.
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.
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...
(a) Write a stack class that is based on a linked list. It can be just...
(a) Write a stack class that is based on a linked list. It can be just pop(), push(), and anything you need for those methods or testing. (b) Write a queue class that is based on a linked list. As above, it can be just enqueue() and dequeue(), as well as anything you need for those methods or testing. (c) Write some test cases, trying to include edge cases. Why did you choose those tests? Did you get the results...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT