Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linked list is a perfect data structure for the implementation of stack and queue. Especially for the queue, it avoids the headaches of wrapping-around manipulation

image text in transcribed

image text in transcribed

image text in transcribed

Linked list is a perfect data structure for the implementation of stack and queue. Especially for the queue, it avoids the headaches of wrapping-around manipulation for a queue implemented by an array. In this project, you are requested to implement both stack and queue by using a linked list (not an array).

In this project, you have an option to find one partner to form a team. However, at most two persons are allowed in each team to complete this project. In a team setting, remember to provide the names of both team members in the document when you submit the completed project to Canvas.

Question 1

Implement a template class Stack as defined by the following skeleton:

template class Stack { private: NodeType* topPtr; // It points to a singly-linked list public: Stack( ); // default constructor: Stack is created and empty Stack(const Stack &x); // copy constructor: implicitly called for a // deep copy void MakeEmpty(); // Stack is made empty; you should deallocate all the // the nodes of the linked list bool IsEmpty( ); // test if the stack is empty bool IsFull( ); // test if the stack is full; assume MAXITEM=5 int length( ); // return the number of elements in the stack void Print( ); // print the value of all elements in the stack in the sequence // from the top to bottom void Push(ItemType x); // insert x onto the stack

void Pop(ItemType &x); // delete the top element from the stack // Precondition: the stack is not empty ~Stack(); // Destructor: memory for nodes needs to be deallocated };

template struct NodeType { ItemType info; NodeType* next; };

In you main( ) routine, you need to test your class in the following cases:

Stack IntStack; int x; IntStack.Pop(x); IntStack.Push(11); IntStack.Push(22); cout IntStack2(IntStack); cout

Stack StringStack; string y; StringStack.Pop(y); StringStack.Push(bob); cout StringStack2 = StringStack; cout

Stack FloatStack; float z; FloatStack.Pop(z); FloatStack.Push(3.1); cout FloatStack2 = FloatStack; cout Linked list is a perfect data structure for the implementation of stack and queue Especially for the queue, it avoids the headaches of wrapping-around manipulation for a queue implemented by an array. In this project, you are requested to implement both stack and queue by using a linked list (not an array) In this project, you have an option to find one partner to form a team. However, at most two persons are allowed in each team to complete this project. In a team setting, remember to provide the names of both team members in the document when you submit the completed project to Canvas. Question 1 Implement a template class Stack as defined by the following skeleton: template class Stack private: NodeType ItemType topPtr; // It points to a singly-linked list public: Stack(); // default constructor: Stack is created and empty Stack(const Stack &); // copy constructor: implicitly called for a // deep copy void MakeEmpty); // Stack is made empty; you should deallocate all the // the nodes of the linked list bool IsEmpty); // test if the stack is empty bool IsFull( ); // test if the stack is full, assume MAXITEM=5 int length(); // return the number of elements in the stack void Print(); // print the value of all elements in the stack in the sequence // from the top to bottom void Push(ItemType x); / insert x onto the stack void Pop(ItemType &); // delete the top element from the stack -Stack); // Destructor: memory for nodes needs to be deallocated // Precondition: the stack is not empty template

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago