It is C++ problems, please explain your each line of code as well.
task-1:
#include <iostream> #include <fstream> #include <string> using std::cout; class Node { public: Node *prev; Node *next; int shares; float pps; Node(int vshares, float vpps) { shares = vshares; pps = vpps; prev = next = nullptr; } }; class dlist { public: Node *head; Node *tail; dlist() { head = tail = nullptr; } ~dlist() { destroy(); } void push_back(int shares, float pps) { Node *node = new Node(shares, pps); if (head == NULL) { head = tail = node; } else { tail->next = node; node->prev = tail; tail = node; } } void destroy() { Node *walk = head; while (walk) { Node *node = walk; walk = walk->next; delete node; } head = tail = nullptr; } }; class stack { public: int maxsize; int count; dlist list; stack(int size) { count = 0; maxsize = size; } void push(int num, float price) { if (count < maxsize) { list.push_back(num, price); count++; } } void pop() { Node *tail = list.tail; if (!tail) { //already empty return; } if (tail == list.head) { //only one element in the list delete tail; list.head = list.tail = nullptr; count--; } else { Node *temp = list.tail->prev; delete list.tail; list.tail = temp; list.tail->next = nullptr; count--; } } void display() { Node *walk = list.tail; while (walk) { cout << "("<< walk->pps << ") "; walk = walk->prev; } cout << "\n"; } }; int main() { stack s(10); string str; cout<<"enter the string"; getline(cin,str); for(int i=0;i<s.length();i++) { s.push(i,str[i]); } s.display(); }
task-2:
It is C++ problems, please explain your each line of code as well. Task 1: Implement/...
(Please do in C++) Implement a Queue using a vector or the STD ::queue:: class Note the difference in what it takes to implement using a char[] array vs a vector or the STD ::queue:: class The user will input a string and the program will return the string with each letter in the string duplicated. Displaying correct Queue implementation. Utilize the conventional methods as needed. Please input String: happy hhaappyy
(java) Please implement your own Dequeue class which has following methods •boolean add(E e)= void addLast(E e) // two methods are the same. You could implement either one • •void addFirst(E e) • •E getFirst( ) = E peek( ) // two methods are the same. You could implement either one •E getLast( ) •E removeFirst() •E removeLast() Case 1 : Queue •Create a queue which is an instance of Dequeue. The queue should perform with given following input and print...
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...
e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...
In C++ Implement a queue data structure using two stacks. Remember a queue has enqueue and dequeue functions. You could use either the array or linked list implementation for stacks and queues. Source for stack array: --------------------------------------------------- #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the...
In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is to complete the implementation of the classes specified as below. Y 1 Your Task You are given a class “Item” that contains one integer value, and two pointers. You are going to build a doubly linked list class DLinkedList. I describe the tasks below. Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure that the copy constructor makes...
lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...
PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement an algorithm to determine the next greater element of an element in an array in Θ(n) time, where 'n' is the number of elements in the array. You could use the Stack ADT for this purpose. The next greater element (NGE) for an element at index i in an array A is the element that occurs at index j (i < j) such that...
Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...
Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...