C++ Data Strucutres and Algorithm
Topic: Queues ADT

#include <iostream>
#include <cstdlib>
#include <queue>
using namespace std;
queue<int> joinQueueSeq(queue<int>&
q1,queue<int>& q2){
queue<int> q;
while (!q1.empty()) {
q.push(q1.front());
q1.pop();
}
while (!q2.empty()) {
q.push(q2.front());
q2.pop();
}
return q;
}
int main(void) {
srand(time(0));
queue<int> q1,q2,q;
int i,temp;
for (i = 0; i < 5; ++i){
temp=rand()%10;
cout<<temp<<" ";
q1.push(temp);
}
cout<<endl;
for (i = 0; i < 10; ++i){
temp=rand()%10;
cout<<temp<<" ";
q2.push(temp);
}
cout<<endl;
q = joinQueueSeq(q1,q2);
cout << "Contents of resultant queue" << endl;
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
return 0;
}
C++ Data Strucutres and Algorithm Topic: Queues ADT Write an application level function with the following...
Queues and Stacks Purpose: To review queues and stacks in Java, and to use the built-in Stack class and Queue interface. The Stack class is a generic class containing these methods: public void push(E value) - pushes a new value onto the Stack public E pop() - pops the next value off of the stack and returns it; throws EmptyStackExceptionl if stack is empty public E peek() - returns the next value on the Stack but does not pop it...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
please write the code in C++ Implement the BinarySearchTree ADT in a file BinarySearchTree.h exactly as shown below. // BinarySearchTree.h // after Mark A. Weiss, Chapter 4, Dr. Kerstin Voigt #ifndef BINARY_SEARCH_TREE_H #define BINARY_SEARCH_TREE_H #include <cassert> #include <iostream> using namespace std; template <typename C> class BinarySearchTree { public: BinarySearchTree( ) : root{ nullptr } { } ~BinarySearchTree( ) { makeEmpty(); } const C & findMin( ) const { assert(!isEmpty()); return findMin( root )->element; } const C & findMax( ) const...
In this assignment you will be implementing two Abstract Data Types (ADT) the Queue ADT and the Stack ADT. In addition, you will be using two different implementations for each ADT: Array Based Linked You will also be writing a driver to test your Queue and Stack implementations and you will be measuring the run times and memory use of each test case. You will also be adding some functionality to the TestTimes class that you created for Homework 1....
1) Write a segment of code (application level) to perform each of the following operations. Assume myStack is an object of the class ArrayStack. You may call any of the public methods of ArrayStack. You may declare additional stack objects. a) Set secondElement to the second element from the top of myStack, leaving myStack without its original top two elements. b) Set bottom equal to the bottom element in myStack, leaving myStack empty. c) Set bottom equal to the bottom...
Queues This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program. Step 1 - Create a new project in Netbeans Use the following naming convention: “Module4_Lastname_Assignment1”. Step 2 - Build a solution You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new...
True or False: 1. Much like a list, a set contains items that are in a particular order. ANSWER 2. With a set, the difference and subset operations are not symmetric. ANSWER 3. The submethod of the set class returns a set containing items in s1 that are not in s2. ANSWER: 4. If SI and s2 are sets, the expression s1.issubset(s2) returns True if s2 is a subset of s1. ANSWER 5.A set is similar to a bag, but...
In C++ and use functions that are asked for, thanks! Implement the BinarySearchTree ADT in a file BinarySearchTree.h exactly as shown below. // BinarySearchTree.h // after Mark A. Weiss, Chapter 4, Dr. Kerstin Voigt #ifndef BINARY_SEARCH_TREE_H #define BINARY_SEARCH_TREE_H #include <cassert> #include <iostream> using namespace std; template <typename C> class BinarySearchTree { public: BinarySearchTree( ) : root{ nullptr } { } ~BinarySearchTree( ) { makeEmpty(); } const C & findMin( ) const { assert(!isEmpty()); return findMin( root )->element; } const C...
help me answer the following questions please 1. Stack (LIFO) & its application 1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Exercises: 1) Which of the following applications may use a stack? A. parentheses balancing program. B. Keeping track of local variables at run time. C. Syntax analyzer for a compiler. D. All of the above. 2) Consider the usual algorithm for determining whether a sequence of parentheses is balanced....
Data Structures & Algorithms . Solve this problem in java(not C language) . Question 1(Queue) Write a program that display list of choices for the user to interact with the program as follow: Queue Operations Menu: 1.Add a new item 2.Delete the first item 3.Show number of items in the Queue 4.Find an item 5.Show all items 6.Exit