
Concept explainers
Can someone help me with this in C++? I have to implement a stack linked list to get these tests on my driver.cpp to work.
////////////////////////////////////////////////////////////////////////
driver.cpp
////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include "stackLL.h"
#include "queueLL.h"
#include "priorityQueueLL.h"
using namespace std;
int main()
{
/////////////Test code for stack ///////////////
///////////// Do not modify anything below ///////////////
stackLL stk;
stk.push(5);
stk.push(13);
stk.push(7);
stk.push(3);
stk.push(2);
stk.push(11);
cout << "Popping: " << stk.pop() << endl;
cout << "Popping: " << stk.pop() << endl;
stk.push(17);
stk.push(19);
stk.push(23);
while (!stk.empty())
{
cout << "Popping: " << stk.pop() << endl;
}
// output order: 11,2,23,19,17,3,7,13,5
stackLL stkx;
stk.push(5);
stk.push(10);
stk.push(15);
stk.push(20);
stk.push(25);
stk.push(30);
stk.insertAt(-100, 3);
stk.insertAt(-200, 7);
stk.insertAt(-300, 0);
//output order: -300,30,25,20,-100,15,10,5,-200
while (!stk.empty())
cout << "Popping: " << stk.pop() << endl;
////////////////////////////////////////////////////////////////////////
stackLL.h
////////////////////////////////////////////////////////////////////////
class stackLL
{
private:
class node
{
public:
//put what you need in here
};
node * top;
public:
stackLL()
{}
//Take care of memory leaks...
~stackLL()
{}
//return true if empty, false if not
bool empty()
{}
//add item to top of stack
void push(int x)
{}
//remove and return top item from stack
int pop()
{}
//add item x to stack, but insert it
//right after the current ith item from the top
//(and before the i+1 item).
void insertAt(int x, int i)
{}
};

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 6 images

- 1. fast please in c++arrow_forwardI need help being able to make a function that adds an item to the back of a doubly linked list to add an animal to the end of the list in C++ Here's what I got so far with the code #include <iostream> #include <string> using namespace std; class node { public: string data;// Data item node* next; // Point to next node }; class linkedList { public: // Variables? (Attributes) node* headptr; // Functions (methods) linkedList() { headptr = nullptr; } // Add an item to front of list void addFront(string x) { // Declare a pointer variable node* p; // Create a new node, and store its address in p p = new node; // Put x into data field of the new node // Can also put p -> data = x, same thing. (*p).data = x; // Set next pointer of node to previous front item (*p).next = headptr; //Update the…arrow_forwardWhy does the C++ inclusion guard on a library interface file need a unique symbol or name? If you assume that the symbol doesn't have to be unique, you may use argument by contradiction to show that it isn't.arrow_forward
- Can you write a swap routine in Java, or in any other language with only call-by-sharing parameters? What exactly should swap do in such a language? (Hint: Think about the distinction between the object to which a variable refers and the value [contents] of that object.)arrow_forwardI was hoping I could get help in describing the mountainarrow_forwardWhat is the implementation of each instruction located in the main function of the following code? This is a sample program, i am trying to teach myself linked list and am having trouble ------------------------------------------------------------------------------- #include <iostream>#include <string> /*** node* * A node class used to make a linked list structure*/ template<typename type>struct node {node() : data(), next(nullptr) {}node(const type & value, node * link = nullptr) : data(value), next(link) {}type data;node * next;}; /*** print_list* @param list - the linked-list to print out* * Free function that prints out a linked-list space separated.* Templated so works with any node.* Use this for testing your code.*/ template<typename type>void print_list(node<type> * list) { for(node<type> * current = list; current != nullptr; current = current->next) {std::cout << current->data << ' ';}std::cout << '\n';} /***…arrow_forward
- Can you implement the StackADT.cpp, Stack.ADT , and StackMain.cpp files, please?arrow_forwardCould I get an example of a program writen in C that uses qsort() to sort its command line vector argv by the length of the strings? This is part of my first project and I don't understand pointers very well. If you have a video on how it is done that would work too. I looked at the meterial provided to me and I still cant rap my head around it. If this is to big of a question if you could baby step me through how pointers work that would be a great help. Thank youarrow_forwardfor Haskell: explain what the following function someFunc does: someFunc m n = take m ((map (\f -> f n) . map (*)) [1..])arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





