can anyone help me my coding C lab exercise one thanks so m

can anyone help me my coding C++ lab exercise one ? thanks so much !!!

Solution

struct Queue { Line* enqueue; Line* dequeue; size_t count; size_t line_capacity; } static void free_line( Line** ppLine ) { Line* toFree = *ppLine; assert(toFree !== NULL); *ppLine = toFree->next; free(toFree); } // theoretically could make this return a bool indicating error/no error, // but it\'s easier to remember that NULL means error. static Line* push_line_before( Line** ppLine, size_t capacity ) { Line* before = *ppLine; Line* new_line = malloc(sizeof(Line) + capacity * sizeof(void **)); if (new_line == NULL) return NULL; new_line->next = before; *ppLine = new_line; /* do initialization the same way you did it... */ return new_line; } static void why_this_way_is_better(Queue* someQueue) { // Queue has no Line-valued member, and yet we can still use the same // functions for a Queue member... free_line( &(someQueue->dequeue) ); push_line_before( &(someQueue->enqueue) ); // ... as the ones for a line member free_line( &(someQueue->dequeue->next) ); push_line_before( &(someQueue->enqueue->next) ); } #include #include #include \"shannon.c\" #include \"queue.h\" // SLIST. typedef struct slist_data_s slist_data_t; struct slist_data_s { int value; SLIST_ENTRY(slist_data_s) entries; }; // SLIST. void slist(int n) { int i=0; slist_data_t *datap=NULL; SLIST_HEAD(slisthead, slist_data_s) head; SLIST_INIT(&head); // Write. for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert: %d\ \", datap->value); SLIST_INSERT_HEAD(&head, datap, entries); } printf(\"\ \"); // Read1. SLIST_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!SLIST_EMPTY(&head)) { datap = SLIST_FIRST(&head); printf(\"Read2: %d\ \", datap->value); SLIST_REMOVE_HEAD(&head, entries); free(datap); } } // LIST. typedef struct list_data_s list_data_t; struct list_data_s { int value; LIST_ENTRY(list_data_s) entries; }; // LIST. void list(int n) { int i=0; list_data_t *datap=NULL; LIST_HEAD(listhead, list_data_s) head; LIST_INIT(&head); // Write. for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert: %d\ \", datap->value); LIST_INSERT_HEAD(&head, datap, entries); } printf(\"\ \"); // Read1. LIST_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!LIST_EMPTY(&head)) { datap = LIST_FIRST(&head); printf(\"Read2: %d\ \", datap->value); LIST_REMOVE(datap, entries); free(datap); } } // STAILQ. typedef struct stailq_data_s stailq_data_t; struct stailq_data_s { int value; STAILQ_ENTRY(stailq_data_s) entries; }; // STAILQ. void stailq(int n) { int i=0; stailq_data_t *datap=NULL; STAILQ_HEAD(stailqhead, stailq_data_s) head; STAILQ_INIT(&head); // Write1 (head). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert head: %d\ \", datap->value); STAILQ_INSERT_HEAD(&head, datap, entries); } printf(\"\ \"); // Read1. STAILQ_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!STAILQ_EMPTY(&head)) { datap = STAILQ_FIRST(&head); printf(\"Read2: %d\ \", datap->value); STAILQ_REMOVE_HEAD(&head, entries); free(datap); } printf(\"\ \"); // Write2 (tail). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert tail: %d\ \", datap->value); STAILQ_INSERT_TAIL(&head, datap, entries); } printf(\"\ \"); // Read1. STAILQ_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!STAILQ_EMPTY(&head)) { datap = STAILQ_FIRST(&head); printf(\"Read2: %d\ \", datap->value); STAILQ_REMOVE_HEAD(&head, entries); free(datap); } } // TAILQ. typedef struct tailq_data_s tailq_data_t; struct tailq_data_s { int value; TAILQ_ENTRY(tailq_data_s) entries; }; // TAILQ. void tailq(int n) { int i=0; tailq_data_t *datap=NULL; TAILQ_HEAD(tailqhead, tailq_data_s) head; TAILQ_INIT(&head); // Forward. printf(\"- Forward\ \"); // Write1 (head). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert head: %d\ \", datap->value); TAILQ_INSERT_HEAD(&head, datap, entries); } printf(\"\ \"); // Read1. TAILQ_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!TAILQ_EMPTY(&head)) { datap = TAILQ_FIRST(&head); printf(\"Read2: %d\ \", datap->value); TAILQ_REMOVE(&head, datap, entries); free(datap); } printf(\"\ \"); // Write2 (tail). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert tail: % d\ \", datap->value); TAILQ_INSERT_TAIL(&head, datap, entries); } printf(\"\ \"); // Read1. TAILQ_FOREACH(datap, &head, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!TAILQ_EMPTY(&head)) { datap = TAILQ_FIRST(&head); printf(\"Read2: %d\ \", datap->value); TAILQ_REMOVE(&head, datap, entries); free(datap); } printf(\"\ \"); // Reverse. printf(\"- Reverse\ \"); // Write1 (head). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert head: %d\ \", datap->value); TAILQ_INSERT_HEAD(&head, datap, entries); } printf(\"\ \"); // Read1. TAILQ_FOREACH_REVERSE(datap, &head, tailqhead, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!TAILQ_EMPTY(&head)) { datap = TAILQ_LAST(&head, tailqhead); printf(\"Read2: %d\ \", datap->value); TAILQ_REMOVE(&head, datap, entries); free(datap); } printf(\"\ \"); // Write2 (tail). for (i=0; ivalue = (int) (randshannon() * 1000.); printf(\"Insert tail: % d\ \", datap->value); TAILQ_INSERT_TAIL(&head, datap, entries); } printf(\"\ \"); // Read1. TAILQ_FOREACH_REVERSE(datap, &head, tailqhead, entries) { printf(\"Read1: %d\ \", datap->value); } printf(\"\ \"); // Read2 (remove). while (!TAILQ_EMPTY(&head)) { datap = TAILQ_LAST(&head, tailqhead); printf(\"Read2: %d\ \", datap->value); TAILQ_REMOVE(&head, datap, entries); free(datap); } }
can anyone help me my coding C++ lab exercise one ? thanks so much !!!Solution struct Queue { Line* enqueue; Line* dequeue; size_t count; size_t line_capacity;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site