Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help with 2 and 3! ``` #include #include struct Node { int val; struct Node *next; }; typedef struct Node * Min_Stack; Min_Stack create_minstack()
please help with 2 and 3!
```
#include#include struct Node { int val; struct Node *next; }; typedef struct Node * Min_Stack; Min_Stack create_minstack() { return NULL; } Min_Stack destroy_minstack(Min_Stack s) { struct Node *p = s; while (p!=NULL) { struct Node *temp = p; p=p->next; free(temp); } } int get_top(Min_Stack stack) { if (stack==NULL) { return -1; } return stack->val; } int get_min(Min_Stack stack) { return 0; } int is_empty(Min_Stack stack) { if (stack==NULL) { return 1; } return 0; } Min_Stack pop(Min_Stack stack) { if (is_empty(stack)) { return NULL; } struct Node * p = stack->next; free(stack); return p; } Min_Stack push(Min_Stack stack, int val) { struct Node *p = (struct Node *) malloc(sizeof(struct Node)); p->val = val; p->next = stack; return p; } void main() { Min_Stack s = create_minstack(); s = push(s, 13); printf("Push 13 "); s = push(s, 15); printf("Push 15 "); s = push(s, 11); printf("Push 11 "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = push(s, 20); printf("Push 20 "); s = push(s, 10); printf("Push 10 "); s = push(s, 9); printf("Push 9 "); s = push(s, 17); printf("Push 17 "); s = push(s, 18); printf("Push 18 "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); s = pop(s); printf("Pop "); printf("Top = %d, Min=%d ",get_top(s),get_min(s)); destroy_minstack(s); return; }
```
Problem 2 (1 pt). Show that (bpa)logbn=nlogbap. Problem 3 (2 pts). Attached is a program minstack.c that has a "min stack", which stores positive integers. Such a stack has the following operations: - Create a minstack - Destroy a minstack - Push an integer value into the minstack - Pop an integer value off the minstack - Get the top integer from the minstack - Get the minimum integer value in the minstack It currently doesn't work, so fix itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started