Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Show what is written by the following segment of code, given that item1, item2.

ID: 3810228 • Letter: S

Question

Show what is written by the following segment of code, given that item1, item2. and item3 are int variables. Stack Typekintco stack; iteml 5: item2 4: item3 m 3 stack Push item2); stack Push item1); stack Push item item3) item2 Top0; stack Pop0; stack. stack Push item2). stack Push (4); itemi stack Topo; stack Popo; item3 endl cout item 1 item2 while stack lsEmpty0) iteml stack Topo: stack Pop0; cout iteml 7.00%) When does a memory leak occur? Please provide an example to show the memory leak. 8. (18%) The Sorted List ADT is extended with a Boolean member function, lsThere. which takes as a parameter an item of type ItemType and determines whether there is an element with this key in the list. (a) Assume the array-based list implementation is used. Please complete the following implementation of this function using binary search algorithm.

Explanation / Answer

6.

Lets say our stack is:

4   5   8 <- top

item2= 8

stack: 4   5

stack: 4    5   9   8   4

itemp1= 4

stack: 4   5   9   8

output: 4 8 3

output: 8 9 5 4

Hence, combined final output:

4 8 3 8 9 5 4

7. A memory leak occurs when we allocate some memory and fails/forget to de-allocate it.

For example,

lets say in main(), we did the following:

int *x= new int;

x=10;

return 0;

//we clearly didnt write: free x;

This is how memory leak occurs

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote