Question
stackLL.hpp #ifndef STACKLL_HPP #define STACKLL_HPP class StackLL { private: struct Node { char key; Node *next; }; // pocharer to item to be popped next
stackLL.hpp
#ifndef STACKLL_HPP #define STACKLL_HPP
class StackLL { private: struct Node { char key; Node *next; };
// pocharer to item to be popped next Node* stackHead;
public: StackLL(); ~StackLL(); bool isEmpty(); void push(char key); void pop(); char peek(); };
#endif -----------------------------------------
stackLL.cpp
#include
using namespace std;
StackLL::StackLL() { stackHead = nullptr; }
StackLL::~StackLL() { while(!isEmpty()) pop(); }
bool StackLL::isEmpty() { return (stackHead == nullptr); }
void StackLL::push(char key) { Node* nn = new Node; nn->key = key; nn->next = nullptr; nn->next = stackHead; stackHead = nn; }
void StackLL::pop() { if(!isEmpty()) { Node* temp = stackHead; stackHead = stackHead->next; delete temp; } else { cout
char StackLL::peek() { if(!isEmpty()) return stackHead->key; else{ cout
QueueLL.hpp
#ifndef QUEUELL_HPP #define QUEUELL_HPP
#include
class QueueLL { private: struct Node { int key; Node *next; };
// item in list to be dequeued next Node* queueFront; // item in list that was most recently enqueued Node* queueEnd;
public: QueueLL(); ~QueueLL(); bool isEmpty(); void enqueue(int key); void dequeue(); int peek(); };
#endif
-------------------------------------------------
QueueLL.cpp
#include
using namespace std;
QueueLL::QueueLL() { queueFront = nullptr; queueEnd = nullptr; }
QueueLL::~QueueLL() { while( !isEmpty() ) dequeue(); }
bool QueueLL::isEmpty() { /*if(queueFront == nullptr || queueEnd == nullptr) return true; return false;*/ return (!queueFront || !queueEnd); }
// TODO void QueueLL::enqueue(int key) { Node *nn = new Node; nn->key = key; nn->next = nullptr;
// TODO Complete this function, handle the case when you're enqueuing in an empty queue }
//TODO void QueueLL::dequeue() { if(!isEmpty()) { // TODO Complete this function, handle the case when your queue becomes empty after dequeuing } else{ cout
int QueueLL::peek() { if( !isEmpty() ) return queueFront->key; else { cout
DriverStack.cpp
#include
using namespace std;
// TODO GOLD - Complete the TODOs in this function bool isValid(string input) { StackLL stack; char x;
// Traversing the input for (int i=0; i // If it is not an opening bracket, then the stack shouldn't be empty if (stack.isEmpty()) return false; //Switch cases for the closing brackets switch (input[i]) { case ')': // TODO first peek and then pop from stack // if the popped character is the matching starting bracket then fine else parenthesis are not balanced break; case '}': // TODO Complete this section (similar to the case above) break; case ']': // TODO Complete this section (similar to the case above) break; } } // If stack is not empty, there are unmatched brackets return (stack.isEmpty()); } int main() { int choice; while(1) { cout cout > choice; cout cout > input; if (isValid(input)) cout } ---------------------------------------------------- DriverQueue.cpp #include int main() { // test queues QueueLL queue; // TC1: queue empty after created? cout // TC2: Push items // TODO SILVER - Complete your enqueue function cout // TC3: Queue not empty after pushing items cout // TC4: peek cout // TC5: pop items // TODO SILVER - Complete your dequeue function cout return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started