Question: typedef struct Node _ s Node; struct Node _ s { void * data; int next; } ; enum ListOutOfBounds { LIST _ OOB _
typedef struct Nodes Node;
struct Nodes
void data;
int next;
;
enum ListOutOfBounds
LISTOOBSTART,
LISTOOBEND
;
#define LISTMAXNUMHEADS
#define LISTMAXNUMNODES
typedef struct Lists List;
struct Lists
Node nodesLISTMAXNUMNODES;
int size;
int head;
int available;
int current;
;
List listcreate
static List listsLISTMAXNUMHEADS;
static bool initialized false;
ifinitialized
forint i ; i LISTMAXNUMHEADS; i
listsihead ;
listsisize ;
listsiavailable ;
initialized true;
for int i ; i LISTMAXNUMHEADS; i
if listsihead
return &listsi;
return NULL;
int ListcountList pList
Ensure pList is not NULL assert is optional
assertpList NULL;
return pListsize;
void ListfirstList pList
if pList NULL pListhead
pListcurrent ;
return NULL;
pListcurrent pListhead;
return pListnodespListheaddata;
void ListnextList pList
assertpList NULL;
if pListcurrent
return NULL; No current item
int currentNodeIndex pListcurrent;
if pListnodescurrentNodeIndexnext
If current item is already at the end of the list, move beyond the end
pListcurrent ;
return NULL;
pListcurrent pListnodescurrentNodeIndexnext;
return pListnodespListcurrentdata;
void ListprevList pList
assertpList NULL;
if pListcurrent
return NULL; No current item
int prevNodeIndex pListhead;
int currentNodeIndex pListcurrent;
if currentNodeIndex pListhead
If current item is at the start of the list, move to before the start
pListcurrent ;
return NULL;
while pListnodesprevNodeIndexnext currentNodeIndex
prevNodeIndex pListnodesprevNodeIndexnext;
pListcurrent prevNodeIndex;
return pListnodesprevNodeIndexdata;
void ListcurrList pList
assertpList NULL;
if pListcurrent
return NULL; No current item
return pListnodespListcurrentdata;
int ListappendList pList, void pItem
assertpList NULL;
if pListsize LISTMAXNUMNODES
return LISTFAIL; List is full
int newNodeIndex pListavailable;
pListavailable pListnodespListavailablenext;
pListnodesnewNodeIndexdata pItem;
pListnodesnewNodeIndexnext ; No next node, as it is the last node
if pListsize
pListhead newNodeIndex;
else
int lastNodeIndex pListhead;
while pListnodeslastNodeIndexnext
lastNodeIndex pListnodeslastNodeIndexnext;
pListnodeslastNodeIndexnext newNodeIndex;
pListsize;
return LISTSUCCESS;
void ListconcatList pList List pList
assertpList NULL && pList NULL;
if pListsize
return; Nothing to concatenate
if pListsize
If the first list is empty, simply copy the second list
pListpList;
else
int lastNodeIndex pListhead;
while pListnodeslastNodeIndexnext
lastNodeIndex pListnodeslastNodeIndexnext;
pListnodeslastNodeIndexnext pListhead;
Update the size of the first list
pListsize pListsize;
Reset the second list
pListhead ;
pListsize ;
pListavailable ;
pListcurrent ;
void printListList pList
assertpList NULL;
printfList: ;
int currentNodeIndex pListhead;
while currentNodeIndex
printfd intpListnodescurrentNodeIndexdata;
currentNodeIndex pListnodescurrentNodeIndexnext;
printf
;
int main
List myList listcreate;
List myList listcreate;
int items;
int numItems sizeofitems sizeofitems;
Append items in a loop
for int i ; i numItems; i
if Listappend fix this code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
