Stack is LIFO data structure (Last In First Out) where the last element entered in stack will be the last one to be out of stack. It has three operations: push() : used to insert an element in stack, pop() : used to delete an element from the stack, top() : used to return the top of the stack i.e. the newest member of the stack. All these operations will take place at the top.
<u>Explanation:</u>
Now, looking at the program, x and y are initialized the values of 2 and 3 respectively. The stack pushes 8 onto the stack making it the first member of the stack. Then the value of x which is 2 is pushed onto the stack. Next, (x+5) = (2+5) = 7 is pushed onto the stack.
Pop() is used to delete hence 7 is popped out from the stack. top() is assigned to y which is 2 in this case and again 2 is popped out from the stack. Now, (x+y) = (2+2) = 4 is pushed onto the stack. And the top() is assigned to x which is 4. 4 is again popped out from the stack. Hence the value of x is 4.
// this function will return 1 if the string sent in arguments is palindrome //else it will return 0
int palindrome(int start_of_string, int end_of_string, string &strr)
{
// base case to check if the string is not empty
if (start_of_string>= end_of_string)
return 1;
if (strr[start_of_string] != strr[end_of_string])
return 0;
// recursive call
return palindrome(++start_of_string, --end_of_string, strr);
}
Answer:
Hi!
The answer to:
a. 6 bits.
b. 9 bits.
c. 26 bits.
Explanation:
a. For the states of the U.S.A, you need 50 or more combinations to represents each element.
<u>If you use 6 bits, the possible combinations are 2⁶ = 64. </u>
b. For days in a year, you need 365 or more combinations to represents each element.
<u>If you use 9 bits, the possible combinations are 2⁹ = 512.
</u>
c. For inhabitants of California, you need 36,457,549 or more combinations to represents each element.
<u>If you use 26 bits, the possible combinations are 2²⁶ = 67,108,864.</u> If you use 25 bits instead of 26, then you have 2²⁵ = 33,554,432 combinations. These possible combinations are not enough to represent each inhabitant.
Answer:
ohhh ok to all transactions.