Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ how would you write this function? bool addStore(Store *s)? I’ve attached

ID: 3911111 • Letter: I

Question

In C++ how would you write this function?

bool addStore(Store *s)? I’ve attached the store header file

2.0.4 The class CustomerList shall create and maintain an ordered linked list of Store objects arranged by Store ID 2.0.4.1 The CustomerList class shall contain the following private variable: Store "m_pHead which shall point to the first Store instance in the list 2.0.4.2 The CustomerList class shall contain the following public functions: bool addStore(Store s), Store removeStore(int ID), Store "getStore(int ID), bool updateStore(int ID, char *name, char *addr, char *city char *st, char *zip), and void printStoresInfo0 2.0.4.2.1 bool addStore(Store *s)-This function shall take a pointer to a Store object which already contains all data on a store. It shall insert the Store object into the linked list in order, sorted by the store ID. It shall return TRUE if the Store was successfully added to the list.

Explanation / Answer

bool addStore(Store *s) { Store *current = m_pHead; Store *previous = NULL; while(current != NULL) { if(current->m_iStoreID > s->m_iStoreID) { // insert new node before current and after previous if(previous == NULL) { // we need to insert as first node, new head s->m_pNext = m_pHead; m_pHead = s; } else { previous->m_pNext = s; s->m_pNext = current; } return true; } else { previous = current; current = current->next; } } // insert at the last previous->m_pNext = s; return true; }