Answer:
Hi
In the first scenario we have
S = []
then:
S=[1],
S=[2,1]
S=[3,2,1]
S=[2,1]
S=[4,2,1]
S=[2,1]
S=[1]
So when it's call the method peek to S, X will be assigned 1
Explanation:
Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out). There are many real-life examples of a stack. Consider an example of plates stacked over one another in the canteen. (Taken from wikipedia)
- The method <em>push</em> is to put the element on the top of the stack
- The method <em>pop</em> is take out the top element of the stack
- The method <em>peek</em> is to see what is the top element of the stack
Operating system interprets commands from a keyboard and mouse
Answer:
int main()
{
int x,y;
bool b1, b2;
cout<<"enter values of x : ";
cin>>x;
cout<<"enter values of y : ";
cin>>y;
b1 = y > x; // false
b2 = x > y; // true
cout << "b1 is = " << b1 << "\n";
cout << "b2 is = " << b2 << "\n";
if (b2)
cout<<endl << "Larger Number" << "\n";
else
cout << "Smaller Number" << "\n";
return 0;
}
sure! what do you wanna chat about?