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

C++ Create a Stack Linked List Create a Stack Linked List of todo items using th

ID: 3592772 • Letter: C

Question

C++ Create a Stack Linked List

Create a Stack Linked List of todo items using the following struct

struct TodoItem
{
std::string todo;
};

• Do NOT add a main method to any of your submitted files.
• DO write your own test drivers to test your code, but do not submit them.
• Your code needs to be readable, efficient, and accomplish the task provided.
• Make sure you delete your dynamically allocated memory in the appropriate
methods!
• When working with array-based implementations, there is a max size
available (set to 5 for this assignment in the header files). Display an error
message if attempting to add to a full array:
“Stack full, cannot add new todo item.”
Or “Queue full, cannot add new todo item.”
Note – this does not apply to linked-list implementations.
• If the stack or queue is empty when you try to pop or peek it, display an error
message:
“Stack empty, cannot pop an item.”
“Stack empty, cannot peek.”
“Queue empty, cannot dequeue an item.”
“Queue empty, cannot peek.”
• Make sure your code is commented enough to describe what it is doing.
Include a comment block at the top of all .cpp files with your name,
assignment number, and course instructor, and anyone you worked with.
• You must implement the functions as specified. You do not need any
additional functions. Each .hpp file has one or more getter methods that are
defined in the header. You do not need to implement these.
• Use the following code for your header files, and name them as indicated. DO
NOT MODIFY.

Header file:

#ifndef HW4_TODO_STACKLINKEDLIST
#define HW4_TODO_STACKLINKEDLIST
#include <string>
struct TodoItem
{
std::string todo;
TodoItem *next;
};
class TodoStackLinkedList
{
public:
TodoStackLinkedList();
~TodoStackLinkedList();
bool isEmpty();
void push(std::string todoItem);
void pop();
TodoItem* peek();
TodoItem* getStackHead() { return stackHead; }
private:
TodoItem* stackHead; // pointer to the TodoItem that will be popped next
};
#endif

Will give thumbs up for correct code with comments to explain what is going on. Thank you.

Explanation / Answer

#include #include #include using namespace std; struct node { int data; node *next; }*front = NULL, *rear = NULL, *p = NULL, *np = NULL; void push(int x) { np = new node; np->data = x; np->next = NULL; if(front == NULL) { front = rear = np; rear->next = NULL; } else { rear->next = np; rear = np; rear->next = NULL; } } int remove() { int x; if (front == NULL) { coutnext; delete(p); return(x); } } int main() { int n, c = 0, x; coutn; while (c