Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be Written in C programming, please take screenshot of output! typedef struct node { ElemType val; struct node *next; } NODE; struct list_struct {

Must be Written in C programming, please take screenshot of output! typedef struct node { ElemType val; struct node *next; } NODE; struct list_struct { NODE *front; NODE *back; }; /************* structs and typedefs *************/ /* * returns pointer to newly created empty list */ LIST *lst_create() { LIST *l = malloc(sizeof(LIST)); l->front = NULL; l->back = NULL; return l; } LIST * lst_from_array(ElemType a[], int n) { int i; LIST *lst; lst = lst_create(); for(i=n-1; i>=0; i--) lst_push_front(lst, a[i]); return lst; } 

CODE FOR LIST ABOVE-HEADER FILE

 /* TODO * * if list is empty, we do nothing and return arbitrary value * otherwise, the last element in the list is removed and its * value is returned. * */ ElemType lst_pop_back(LIST *l) { return DEFAULT; } /* TODO * For full credit, you cannot allocate any new memory! * * description: see header file */ void lst_reverse(LIST *l) { } /* * removes first occurrence of x (if any). Returns * 0 or 1 depending on whether x was found */ int lst_remove_first(LIST *l, ElemType x) { NODE *p; NODE *tmp; if(l->front == NULL) return 0; if(l->front->val == x) { lst_pop_front(l); return 1; } // lst non-empty; no match on 1st elem p = l->front; while(p->next != NULL) { if(x == p->next->val) { tmp = p->next; p->next = tmp->next; if(tmp == l->back) l->back = p; free(tmp); return 1; } p = p->next; } return 0; } int lst_remove_all_slow(LIST *l, ElemType x) { int n=0; while(lst_remove_first(l, x)) n++; return n; } /** DONE * function: lst_sra_bad_case (sra: "slow_remove_all") * * description: constructs a list of length n such that * the above function takes quadratic time to remove * all occurrences of a specified value. * * By convention, the specified value will be 0 */ LIST *lst_sra_bad_case(int n) { // push n/2 0's on front of list followed // by n/2 1's // // thus 1st half of list is all 1's and 2nd // half is all 0's lst = lst_create(); while(n > n/2) { lst_push_front(lst, 0); n--; } while(n > 0) { lst_push_front(lst, 1); n--; } return NULL; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Wiley Ifrs 2005 Interpretation And Application Of International Accounting And Financial Reporting Standards

Authors: Barry J Epstein ,Abbas Ali Mirza ,Peter Walton

Revised Edition

0471668370, 978-0471668374

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago