Show what is written by the following segment of given that item1. item2, and co
ID: 3810226 • Letter: S
Question
Show what is written by the following segment of given that item1. item2, and code, item3 are what int variables StackType stack; item1 = 5; item2 = 4; item3 = 3;stack. Push item2, 4: item3 s 3: item2); stack Push item 1); stack Push item1 item3) item2 stack Topo; stack.Popo: stack Push item3 item3): stack Push item2) stack Push(4); itemi Topo: stack. Popo: cout item item2 item3 endl while (stack usEmptyo) lem stack Topo: stack Pop0; cout item 1 cc When does a memory leak occur? Please provide an example to show the memory leak. The Sorted List ADT is extended with a Boolean member function, Is there, which takes as a parameter an item of type Item Type and determines whether there is an element with this key in the list. is used. Please complete the following (a) Assume the array-based list implementation implementation of this function using binary search algorithm.Explanation / Answer
StackType<int> stack;
Item1 =5; item2 = 4; item 3 = 3;
stack.push(item2) // >4
stack.push(item1) //>5,4
stack.push(item1 + item3 ) // >8, 5, 4
item2 = stack.top(); // item 2 = 8
stack.pop() // >5,4
stack.push(item3 * item3) // >9, 5, 4
stack.push(item2) // > 8, 9, 5, 4
stack.push(4) // >4, 8, 9, 5, 4
item1 = stack.top() //item1 = 4
stack.pop() //>8,9,5,4
cout<<item1<<” ”<<item2<<” “<<item3<<endl //4 8 3
while (!stack.isEmpty()) {
item1 =stack.top();
cout<<item1<<“ ”;
stack.pop();
} //8 9 5 4
/* Output of the code is:
4 8 3
8 9 5 4 */
7. Memory leak occurs when we create a memory in heap and do not delete it.
Memory leaks are particularly serious issues servers which by definition never terminate.
Example:
int main()
{
int count = 0;
char *ptr = NULL;
for(count=0; count<10; count++) {
ptr = (char *)malloc(sizeof(char) * 30);
}
free(ptr);
return count;
}
we have 10 allocations of size 30. Every allocation, with the exception of the last, is lost. If no pointer is pointed to the allocated block, it is unrecoverable during program execution causing a memory leak.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.