Computers and Technology
Computers and Technology, 10.12.2021 21:10, brien301

Please write this in C. Regarding the following linked lists:
typedef struct _orderList
{
foodNode *head; // Pointer to first food item for the order (alphabetical)
int count; // Number of food items in the order
} orderList;
Where foodNode is defined as
typedef struct _foodNode
{
char *data; // Food Item Name
struct _foodNode *next;
} foodNode;
You will provide the following functions to operate on orderLists:
orderList *createItem(). Creates (using dmalloc() -- see below) an instance of an orderList struct, initializes its fields and returns a pointer to the newly allocated struct.
int insert(char *str, orderList *s). Places a new string in the orderList by inserting a new foodNode into its linked list and increments count. The food items will be inserted into the orderList in alphabetical order (use strcmpi() below for this). Duplicate strings (ignoring case) will not be allowed in the orderList. Returns 0 if the insertion was successful, and 1 otherwise.
void printItems(orderList *s). Displays the elements of the orderList with each string on a new line.
You may find the following two functions useful:
/* compares strings for alphabetical ordering */
int strcmpi(char *s, char *t)
{
while (*s && tolower(*s) == tolower(*t))
{
s++;
t++;
}
return tolower(*s) - tolower(*t);
}
/* allocates memory with a check for successful allocation */
void *dmalloc(size_t size)
{
void *p = malloc(size);
if (!p)
{
printf("memory allocation failed\n");
exit(1);
}
return p;
}
Always check the pointer returned by malloc() for successful memory allocation. You may use the dmalloc() function above in place of malloc() to ensure that this is always done. You may also find it convenient to write a function char *stringcopy(char *s) which creates (with dmalloc()) a copy of the string parameter.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:20, mahaleyrenee1195
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
image
Computers and Technology, 23.06.2019 00:00, brooklyn4932
What engine component is shown in the above figure?
Answers: 1
image
Computers and Technology, 23.06.2019 06:00, jack487
How can a user delete a drawing object
Answers: 1
image
Computers and Technology, 23.06.2019 13:10, BrianKeokot4534
What is domain name system (dns)? allows dynamic ip address allocation so users do not have to have a preconfigured ip address to use the network converts ip addresses into domains, or identifying labels that use a variety of recognizable naming conventions the efficient coexistence of telephone, video, and data communication within a single network, offering convenience and flexibility not possible with separate infrastructures the integration of communication channels into a single service
Answers: 2
Do you know the correct answer?
Please write this in C. Regarding the following linked lists:
typedef struct _orderList

Questions in other subjects:

Konu
Mathematics, 10.11.2020 23:00
Konu
Health, 10.11.2020 23:00