Data structures:
Assume we have a stack named s. What will be the values stored in s after the following operations(from bottom to top)?
s.push(1);
s.push(5);
s.push(6);
s.pop();
s.push(3);
s.push(4);
s.push(8);
s.pop();
s.pop();
s.push(1); -> stack is [1] with 1 at top. s.push(5); -> stack is [1, 5] with 5 at top. s.push(6); -> stack is [1, 5, 6] with 6 at top. s.pop(); -> stack is [1, 5] with 5 at top. s.push(3); -> stack is [1, 5, 3] with 3 at top. s.push(4); -> stack is [1, 5, 3, 4] with 4 at top. s.push(8); -> stack is [1, 5, 3, 4, 8] with 8 at top. s.pop(); -> stack is [1, 5, 3, 4] with 4 at top. s.pop(); -> stack is [1, 5, 3] with 3 at top. What will be the values stored in s after the following operations(from bottom to top)? Answer: [1, 5, 3] with 3 at top.
Data structures: Assume we have a stack named s. What will be the values stored in...
A stack S of integers initially contains the following data: 6 (top) 2 7 3 The following code is then executed: int x = S.pop(); int y = S.pop(); int z = S.pop(); S.push(x + y); int w = S.pop(); S.push(w + z); After this code has been executed, what are the contents of the stack? A. 8 10 B. 10 8 C. 15 3 D. 10 8 6 3
stack.h template class Stack{ public: Stack(int max = 10); ~Stack() {delete [] stack;} bool isEmpty() const { return top == -1; } bool isFull() const { return top == MaxStackSize; } T peek() const; void push(const T& x); void pop(); private: int top; int MaxTop; T * stack; } source.cpp What is printed by the following program segment? Stack s; int n; s.push(4); s.push(6); s.push(8); while(!s.isEmpty()) { n = s.peek(); cout << n << ‘ ‘; s.pop(); } cout<< endl;...
Given an empty stack s, an input array a = {1,2,3,4}. What is printed when the following function is executed? public void pushAndPop(Stack s, int[] a){ s.push(a[0]); s.push(a[1]); System.out.println(s.pop()); s.push(a[2]); System.out.println(s.pop()); s.push(a[3]); System.out.println(s.pop()); System.out.println(s.pop()); } A.2, 1, 4, 3 B.2, 3, 1, 4 C.1, 2, 3, 4 D.2, 3, 4, 1
C++ Data structures and Algorithms Use a Queue to reverse a stack in place. Assume you are given a stack of string values like Stack s; using a Queue, cause all of the items in the stack to be reversed. For example, if you have the following contents on the stack s Top --- bird cat dog turtle ----- Bottom After you run your code, you stack contents should look like Top --- turtle dog cat bird ----- Bottom
Must be written in C++ Please
Lab 11 Due Date: April 25, 2019 Total Points: 15 points The purpose of this lab is to implement and test a static and dy namic stack Part 1: Static Stack In this part, you are going to design a stack of characters. Assume a simple static array implementation. Complete the code below as specified by the comments below const int MAX- 5 // define an alias for the element type class Stack private:...
Collections (a) What are generic types and what is their importance in ADTs for collections? (b) How are the ADTS of stacks and queues similar? How does their behaviour differ? (c) What is the difference between a static and a dynamic data structure? Why are static structures such as arrays often used in the background for dynamic data structures (e.g., in Java's ArrayList)? What issues does this raise and how are they generally resolved? (d) Suppose the following fragment occurs...
What is the output from running the following code snippet. void mystery(Queue<int>& q) { Stack<int> s; while (!s.isEmptyQueue()) { s.push(q.front()); q.deleteQueue(); } while (!s.isEmptyStack()) { q.addQueue(2 * s.top()); s.pop(); } } Queue q; q.addQueue(8); q.addQueue(4); q.addQueue(18); q.addQueue(7); q.addQueue(5); mystery(q); cout << "["; while (!.isEmptyQueue()) { cout << " " << q.front(); } cout << " ]" << endl;
help finish Queue, don't think
I have the right thing.
# 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...
In C++ Implement a queue data structure using two stacks. Remember a queue has enqueue and dequeue functions. You could use either the array or linked list implementation for stacks and queues. Source for stack array: --------------------------------------------------- #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the...
Data Structures and Algorithm Analysis
illustrate the result of each operation in the sequence PUSH(S,
4), PUSH(S, 2), POP(), PUSH(S, 3), PUSH(S, 9), POP(), and PUSH(S,
0) on an initially empty stack S stored in array S[1..6].
1 2 3 4 5 6 7 1 2 3 4 5 6 7 15 6 2 9 17 3 S15 6 29 173 top[S] = 4 top[S] = 6 top[S] = 5