Assumption: Using the stack and queue’ tutorial. Stack: bool top(data); void push(value); bool pop(data); bool isEmpty(); int size(); Queue: bool front(data); void enqueue( bool dequeue( bool isEmpty(); int size(); Question 1: a) Write code to construct c và Kỹ thuật máy tính ọc máy tính 1 Tut 3: Stack Queue stack and queue’s methods described below to solve all questions inside this data); Get the value at top of stack, assign that value into ‘data’ and return true. If stack is empty, return value); Push a value on the top of stack. data); Remove the object at the top of this stack, assign value into ‘data’ variable, returns falseotherwise. Check if whether stack is empty. Return stack is empty and returnfalseotherwise. Return the number of elements in stack. data); Get the value at front of queue, assign that value into ‘data’ and return true. If queueis empty, return value); Add a value at rear of queue data); Removes the object at the front of this value into ‘data’ variable, returns true if success and false otherwise. Check if whether queueis empty. Return queueis empty and returnfalse otherwise. Return the number of elements in queue to construct a stack and a queue as follow all questions inside this stack, assign that value into . If stack is empty, return false; the object at the top of this stack, assign variable, returns true if success and Check if whether stack is empty. Return true if otherwise. in stack. et the value at front of queue, assign that value into . If queueis empty, return false; of this queue, assign variable, returns true if success and is empty. Return true if otherwise. queue.
Khoa Khoa học c Kỹ K thuật máy tính Bộ môn Khoa họ ọc máy tính Tut 3: Stack& Queue Assumption: Using the stack and queue’s queue’ methods described below to solve all questions inside this tutorial Stack: bool top(&data); &data); // Get the value at top of stack, assign that value into //‘data’ and return true If stack is empty, return false; void push(value); value); // Push a value on the top of stack bool pop(&data); &data); // Remove the object at the top of this stack, assign // value into ‘data’ variable, returns true if success and // falseotherwise bool isEmpty(); // Check if whether stack is empty Return true if // stack is empty and returnfalseotherwise otherwise int size(); // Return the number of elements in stack Queue: bool front(&data); &data); // Get et the value at front of queue, assign that value into //‘data’ and return true If queueis empty, return false; void enqueue( value); // Add a value at rear of queue bool dequeue( &data); // Removes the object at the front of this queue, assign // value into ‘data’ variable, returns true if success and // false otherwise bool isEmpty(); // Check if whether queueis is empty Return true if // queueis empty and returnfalse otherwise int size(); // Return the number of elements in queue queue Question 1: a) Write code to construct a stack and a queue as follow Khoa Khoa học c Kỹ K thuật máy tính Bộ môn Khoa họ ọc máy tính b) Add code to change above stack and queue in (a) to: c) Add code to change above stack and queue in (b) to:(without without using any primitive value) e.g push a primitive value Stack s; s.push(1); Question 2: A Stacky program creates create a stack and pushes following values orderly Stack s; Double a; s.push(0); s.push(1); s.push(2); s.push(3); s.push(4); s.push(5); s.push(6); s.push(7); s.push(8); s.push(9); Some pop and cout statements are inserted randomly after first push statement statement Khoa Khoa học c Kỹ K thuật máy tính Bộ môn Khoa họ ọc máy tính For example: Stack s; Double a; s.push(0); s.push(1); if(s.pop(a)) cout