Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me out, need ASAP. Please use c++ programming language. And also I n

ID: 3842664 • Letter: P

Question

Please help me out, need ASAP. Please use c++ programming language. And also I need output and codes, please. Thanks in advance.

SHORT PROGRAMMING TASKS

Object Orientated Programming or Procedural Programming are ok.

To receive full credit, programmers must apply coding conventions for code block indentation, comments describing methods/classes, white space between code blocks, and variable/method/class naming conventions.

Implement a Queue on a char Linked Lists. Do not use ::Queue:: class from the STD library for this example.

The user will input a string and the program will output the string backwards. Displaying correct Stack implementation.

Utilize the conventional methods as needed.

push()

pop()

empty()

peek()

peek()

Attach Snipping Photos of source code and output below.

Sample Execution

Please input String:

happy

yppah

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;

//Node class to storing data
class Node
{
   public:
   char data;
   Node *next;
   Node(char d)
   {
       data = d;
       next = NULL;
   }
};

//Stack implementation using char
class Stack
{
   private:
   Node *back;
   int size;
   public:
   Stack()
   {
       back = NULL;
       size = 0;
   }
   Stack(string value)
   {
       size = 0;
       for(int i=0; i<value.length(); i++)
           push(value.at(i));
      
   }
   void push(char ch)
   {
       Node *node = new Node(ch);
       if(back == NULL)
           back = node;
       else
       {
           node->next = back;
           back = node;
       }
       size++;
   }
   char pop()
   {
       char data = back->data;
       back = back->next;
       size--;
       return data;
   }
   char peek()
   {
       return back->data;
   }
   bool empty()
   {
       return size==0;
   }
};
//Main function
int main() {
   string input;
   cout<<"Please input string: ";
   cin>>input;
   cout<<endl;
   Stack stack(input);
   while(!stack.empty())
       cout<<stack.pop();
   return 0;
}

OUTPUT: