Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a list from an array: #include #include #include list.h typedef struct node { ElemType val; struct node *next; } NODE; struct list_struct { NODE

Creating a list from an array:

#include

#include

#include "list.h"

typedef struct node {

ElemType val;

struct node *next;

} NODE;

struct list_struct {

NODE *front;

NODE *back;

};

LIST *lst_create() {

LIST *l = malloc(sizeof(LIST));

l->front = NULL;

l->back = NULL;

return l;

}

void lst_push_front(LIST *l, ElemType val) {

NODE *p = malloc(sizeof(NODE));

p->val = val;

p->next = l->front;

l->front = p;

if(l->back == NULL) // was empty, now one elem

l->back = p;

}

void lst_push_back(LIST *l, ElemType val) {

NODE *p;

if(l->back == NULL) // list empty - same as push_front

lst_push_front(l, val);

else { // at least one element before push

p = malloc(sizeof(NODE));

p->val = val;

p->next = NULL;

l->back->next = p;

l->back = p;

}

}

/**

* TODO

* function: lst_from_array

*

* description: creates a new list populated with the

* elements of array a[] in the same order as

* they appear in a[] (element at a[0] will be the

* first element in the list and so-on). List is

* returned as a LIST pointer.

*

* Parameter n indicates the length of the given array.

*

* runtime requirement: THETA(n)

*/

LIST * lst_from_array(ElemType a[], int n) {

return NULL; //placeholder

}

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago