Answer the following questions for the given code snippet. 1- int main (){ 2 Queue q; 3 int i; 4 5 cin>>i; 6 7 while (i
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Answer the following questions for the given code snippet. 1- int main (){ 2 Queue q; 3 int i; 4 5 cin>>i; 6 7 while (i
questions for the given code snippet. 1- int main (){ 2 Queue q; 3 int i; 4 5 cin>>i; 6 7 while (i != -1){ if (i %2 8 0) 9 q. enqueue(i); 10 cin>>i; 11 } 12- while (!q.isEmpty()) { 13 q.dequeue(); 14 cout <<i << endl; 15 } 16} 1- Given the following input, what does the above C++ code display? 1-2-3-4-5-6-7-8-9-10--1 2- What if a stack was used instead of queue (push instead of enqueue and pop instead of dequeue)? What does the above C++ code will display then given The same set of input?
Answer the following