Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB 1: ARRAY IMPLEMENTATION OF STACK AND LINKED LIST IMPLEMENTATION OF STACK 1. Answer the following questions. a) Write declaration for a stack implementation array

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

LAB 1: ARRAY IMPLEMENTATION OF STACK AND LINKED LIST IMPLEMENTATION OF STACK 1. Answer the following questions. a) Write declaration for a stack implementation array that store student names. The size of the array is 10. Declare an instance of stack using variable aStack. b) Write a push() operation that will insert string value to the stack. c) Write a pop () operation that will delete an item from the top stack. d) Write a source codes that will print the value at the top of the stack. If the stack is empty, write an appropriate message. 2. Extended programming exercise on stack: a) Two stacks of the same type are the same if they have the same size and their elements at the corresponding positions are the same. Write a function that will return true if two stacks of the same type are the same and false otherwise. b) Add the following operation to the stack class in order to copy the elements of a stack in reverse order to another stack. void reverseStack (.....); c) Write the implementation of the function and test the function. d) Repeat the programming exercise for linked-list implementation. 3. Execute the programs (Program 8.15 and Program 8.16) given below for array- based stack and observe the output when the following operations are performed: a) push a, push b, push c, push d, push a, push b, push c, push d, push e, push d, and push f. b) push a, push b, pop, push c, push d, pop, push a, and push b c) push a, push b, pop, push c, push d, pop, push a, pop, pop, pop, and pop d) Repeat the operations for a stack implemented with link list. 7/Program 8.15 - array based stack 2 const int size = 10; 1 class stack 3 4 5 6 7 8 9 10 private : // data declaration int top; char data[size]; public : // function declaration 11 12 13 14 15 16 17 18 void createStack(); void push(); // insert operation void pop(); // delete operation int stackTop(); // get top value bool isFull(); // check if stack is Pull bool isEmpty(); // check if stack is empty 20 19 void stack:: createStack(); top = -1; 21 } 22 23 bool stack::isFull() { 24 return bool( top == size-1); 25] 26 27 bool stack::isEmpty() { 28 return bool( Top == -1); 29 } 30 31 void stack::push() { 32 char newitem; 33 34 cout > newitem; 36 if (isFull()) // check whether stack is full 37 cout > item;newnode = new (stack); 31 if( newnode = NULL) cout data = item; 36 newnode->next = head; 37 head = newnode; 38 // end if 39 } //end push operation 40 41 void stack::pop() { 42 nodeStack delnode; 43 44 if (isEmpty()) cout data next; delete (delnode); 50 // end else 51 } // end pop 52 53 int stack::stackTop() { 54 if (isEmpty()) cout data; 57 ) // end check item at top 58 Answer all questions in this section. 7/Program 8.17 Stack s; char charValue; cout

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

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions