please help in C++
LAB EXERCISE: (70 Minutes) In the main() method: 1. Create a new object of the queue linked list called testQueue: QueueLL testQueue = new QueueLL(); 2. Ask the user to add the element to the queue, the user can keep inputting values for as long as they wish. If the user enters "O", this means the end of the input. 3. Print all nodes in the testQueue estQueue->printQueue(); 4. Test the SmallestLargest () method that was written in the QueueLL class. Add the following lines of code in the main class: if (myQueue->isEmpty()) { cout << "> Error: cannot find largest and smallest nodes (the queue is empty)" << endl; } else { cout << ">Displaying smallest and largest nodes:"; cout << "> "; myQueue->SmallestLargest(); cout << endl; }
After enqueuing 6 elements as random e.g. 10, 20, 35, 26, 53, 90, 0 in the queue, it will display the following output: run: What are values do you want to enqueue: 10 20 35 26 53 90 0 10 was successfully enqueued into the queue. 20 was successfully enqueued into the queue. 35 was successfully enqueued into the queue. 26 was successfully enqueued into the queue. 53 was successfully enqueued into the queue. 90 was successfully enqueued into the queue. Printing All Nodes: 10, 20, 35, 26, 53, 90, Displaying smallest and largest nodes : Smallest element in the queue is 10 largest element in the queue is 90 5. Create a new object of the queue linked list called myQueue. 6. Add the following methods: a) a method fillQWithRandomNumber(QueueLL myQueue) to enqueuing 10 elements at random values (between 0 and 1000) in the myQueue. Note: · Call the fillQWithRandomNumber(myQueue) method to fill myQueue. • In the fillQWithRandomNumber(myQueue) method • Repeat the following for all elements: o Generate a random integer number (between 0 and 1000), o Call enqueue () method to create a new node and insert a value to the my Queue. my Queue-> enqueue (value); // to enqueue a new node to the myQueue.
b) a method deleteNode(QueueLL myQueue, int data) to delete a node from a queue using only enqueue() and dequeue() methods. You can use another queue for this purpose. Hint: You have a queue which contains 10 random numbers between 1 and 1000. Your task is to write a code in main class which deletes a particular node from the queue. However, in this process, you can use only enqueue() and dequeue() methods. In this process, you will dequeue() all elements from first queue, except the one which you want to delete, and enqueue() these elements in the second queue. Now all elements of first queue, except the one which you have deleted, are in the second queue. Finally, dequeue all elements of the second queue and enqueue them in the original queue. Sample Run (for 10 elements): Delete Node from the queue (using 2nd queue) <<<<<<<<< Before deleting value, elements of the queue are as follows: 993, 148, 73, 628, 528, 394, 682, 339, 126, 463, Please enter an int value (between 1 and 1000) to delete from the queue: 394 After deleting value 394, elements of the queue 1 are as follow 993, 148, 73, 628, 528, 682, 339, 126, 463, c) a method OddEvenNode(QueueLL MmyQueue) to copy even nodes of a queue in a second queue and odd nodes in a third queue. After the process is over, the first queue should be empty. Hint: You have a queue which contains 10 random numbers between 1 and 1000. Your task is to write a code in main class which enqueues all even elements of the first queue in the second queue and all odd elements in the third queue. During this process, you should use only enqueue() and dequeue() methods. At the end of the process, the first queue should be empty.
Sample Run (for 10 elements): Even and odd value queues <<<<<<<<< . Element of queue 1 are as follows: 61, 812, 438, 100, 70, 477, 21, 626, 251, 537 Elements of queue 2 are as follows: 812, 438, 100, 70, 626, Elements of queue 3 are as follows: 61, 477, 21, 251, 537, d) a method reveres Element(QueueLL myQueue) to reverse the elements of a queue. You can use stack for this purpose. Hint: You have a queue which contains 10 random numbers between 1 and 1000. Your task is to write a code in main class which reverses all elements of the queue. In this process, you will first dequeue all elements of the queue and push them onto the stack. Then you will pop all elements of the stack and enqueue them into the queue. Sample Run (for 10 elements): Reverse the elements of a queue <<<<<<<<< Element of a queue are as follows: 606, 453, 366, 560, 47, 326,792, 299, 281, 153, Element of the queue after reversing are as follows 153, 281, 299, 792, 326, 47, 560, 366, 453, 606,
please help in C++
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am