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...
One way to implement a queue is to use a circular linked list. In a circular...
One way to implement a queue is to use a circular linked list. In a circular linked list, the last node’s next pointer points at the first node. Assume the list does not contain a header and that we can maintain, at most, one iterator corresponding to a node in the list. For which of the following representations can all basic queue operations be performed in constant worst time? Justify your answers. Maintain an iterator that corresponds to the first...
Programming Project – Deques, Stacks & Queues General Description: Design and develop array based and linked...
Programming Project – Deques, Stacks & Queues General Description: Design and develop array based and linked list-based implementations for the Dequeue ADT. Your implementation must support generic data types using C++ templates. Develop Adapter Files to provide Stack and Queue functionality for the Deques. Definitions: You should implement the ADTs precisely as described in the following partial header files. Deque.h template class Deque { public:         Deque();                    //constructor         ~Deque();                 //destructor         void insertFront(const E& e);...
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)
Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
// 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...
Write a template class that implements an extended queue (use singly Linked List) in c++ please...
Write a template class that implements an extended queue (use singly Linked List) in c++ please create 3 classes please create 3 classes please create 3 classes please create 3 classes please create 3 classes Ex: ExtendedQueue int_queue; ExtendedQueue double_queue; ExtendedQueue char_queue; –Write a program to test this template class. you have to use inheritance so you will create 3 classes : so you will create 3 classes : so you will create 3 classes : so you will create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT