Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

:In C++, Create A Stack Using Linked Lists. To Do This The Class Stack Has Declared Some Useful Variables, Pointers, Functions, And The Class Node.

:In C++, Create A Stack Using Linked Lists. To Do This The Class Stack Has Declared Some Useful Variables, Pointers, Functions, And The Class Node. Pointers &Amp; Variables: Head: This Pointer Will Always Point To The Top Node Of Your Stack, When You Push Use This Pointer To Locate The Top Node. Tail: This Pointer Will Always Point To The Bottom Node Of The

In C++, create a Stack using linked lists. To do this the class Stack has declared some useful variables, pointers, functions, and the class Node.

Pointers & Variables:

1. Head: This pointer will always point to the top Node of your stack, when you push use this pointer to locate the top Node.

2. Tail: This pointer will always point to the bottom Node of the stack, set this pointer when the stack pushes its first item.

3. Count: Use this integer variable to store the number of items in your Stack, increase when you push, decrease when you pop.

Functions:

1. MyStack: Class constructor, initialize the pointers & variables to reflect an empty Stack.

2. Push(string): Push a new Node with info=string. Update, if necessary, head, tail and count.

3. Pop: Removes the top Node of the stack and delete the Node to save memory. Update, if necessary, head, tail and count.

4. Top: Returns the string info from the top Node.

5. Size: Returns the number of items in your Stack.

Class Node:

1. String info: This variable will store the string of the Node.

2. Node* next: This pointer will store the address to the next Node in the Linked List.

Included Files:

MyStack.cpp

#include "MyStack.h"

//constructor : initiazlize the head and tail field from MyStack class MyStack::MyStack() { head = nullptr; tail = nullptr; count = 0; }

/* - Create the new Node and initialize the fields of class Node (info and next) - update the head, tail and count accordingly

Hint: To update head and tail properly, You have to consider two scenarios: 1. If there is no element in the stack and this is the first one going to the stack 2. If there is another head in the stack */ void MyStack::push(string s) { // TO DO }

/* First, Check if the stack is empty or not. If not, update the head,tail and count accordingly. Don't forget to release memory using delete Hint: To update head and tail properly, You should consider two different scenario: 1. If MyStack has more than one element 2. If MyStack has exactly one element */ void MyStack::pop() { // TO DO }

/* What is always referring to the top element? If stack is empty, return ""; */ string MyStack::top() { // TO DO }

/* What keep track of number of elements in the stack? */ int MyStack::size() { // TO DO }

MyStack.h

#ifndef MyStack_H #define MyStack_H

#include

using namespace std;

class MyStack {

public: MyStack(); // the constructor void push(string s); // push string s to the stack void pop(); // remove the top string from the stack string top(); // return the top string of stack int size(); // return size of stack

class Node // Yes, you can have a class inside another class, use this class for your linked list implementatin of stack { public: string info; Node* next; };

private: Node* head; // pointer to the head of linked list Node* tail; // pointer to the tail of linked list int count; // keep track of size of stack

};

#endif

Source.cpp

#include #include "MyStack.h"

using namespace std;

int main() { // Your output should be Yes! You Did It!

MyStack s; s.push("First"); s.push("Hello"); s.push("It!"); s.push("Did"); s.push("You"); s.push("Yes!"); s.push("Bye"); s.pop(); // pop: Bye cout s.pop(); // pop: Yes cout s.pop(); // pop: You cout s.pop(); // pop: Did cout s.pop(); //pop: It! s.pop(); // pop: Hello

cout

system("pause"); return 0; }

q21: Use Your TestDistribution Class From Project 13 To Experiment With Different Values Of The Multiplier, Increment, And Modulus. Prepare A Text File (*.Txt File) Which Contains Good Values Of The Multiplier, Increment,

Use your TestDistribution class from project 13 to experiment with different values of the multiplier, increment, and modulus. Prepare a text file (*.txt file) which contains good values of the multiplier, increment, and modulus that you found, together with the output of your TestDistribution program when run with these numbers, and

not good values of the multiplier, increment, and modulus that you found, together with the output of your TestDistribution program when run with these numbers. Mark which values are good and which are not good in the text file

q22: A Government Proposes To Build A Correctional Services Facility Either In Claymore Or East Sydney Neighbourhood. Argue The Possibility Of Using Artificial Intelligent To Make A Decision For This Scenario.

A government proposes to build a correctional services facility either in Claymore or East Sydney neighbourhood. Argue the possibility of using artificial intelligent to make a decision for this scenario.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Signals and Systems using MATLAB

Authors: Luis Chaparro

2nd edition

978-0123948120

Students also viewed these Programming questions

Question

Simplify 1) sin x cot x 2) 3) cosx 1+sin x sinx 1+0051

Answered: 1 week ago