Menu

(Solved) : Additional Files Another Question Https Wwwcheggcom Homework Help Questions Answers Trying Q44117851 . . .

Additional Files For Another Question:https://www.chegg.com/homework-help/questions-and-answers/trying-figure-needs-headersh-file-written-print-function-qualities-header-file-main-needs–q44110665?trackid=LbXsaXz3

insertionSort.c

/*————————————————————————–* *—- —-* *—- insertionSort.c —-* *—- —-* *—- This file defines a function that implements insertion —-* *—- sort on a linked-list of integers. —-* *—- —-* *—- —- —- —- —- —- —- —- —- —-* *—- —-* *—- —-* *—- —-* *————————————————————————–*/#include “headers.h”// PURPOSE: To sort the linked-list of nodes pointed to by ‘nodePtr’ using// the insertion sort algorithm. Returns the first node of the sorted// list.struct Node* insertionSort (struct Node* nodePtr ){ struct Node* startPtr = NULL; struct Node* endPtr = NULL; struct Node* lowestPtr; struct Node* lowestPrevPtr; while (nodePtr != NULL) { struct Node* prevPtr; struct Node* run; lowestPrevPtr = NULL; lowestPtr = nodePtr; for (prevPtr = nodePtr, run = nodePtr->nextPtr_; run != NULL; prevPtr = run, run = run->nextPtr_ ) { if (lowestPtr->value_ > run->value_) { lowestPtr = run; lowestPrevPtr = prevPtr; } } if (lowestPrevPtr == NULL) { if (startPtr == NULL) { startPtr = endPtr = lowestPtr; } else { endPtr->nextPtr_ = lowestPtr; endPtr = endPtr->nextPtr_; } nodePtr = nodePtr->nextPtr_; endPtr->nextPtr_ = NULL; } else { if (startPtr == NULL) { startPtr = endPtr = lowestPtr; } else { endPtr->nextPtr_ = lowestPtr; endPtr = endPtr->nextPtr_; } lowestPrevPtr->nextPtr_ = lowestPtr->nextPtr_; endPtr->nextPtr_ = NULL; } } print(startPtr); return(startPtr);}

mergeSort.c

/*————————————————————————–* *—- —-* *—- mergeSort.c —-* *—- —-* *—- This file defines a function that implements merge-sort on —-* *—- a linked-list of integers. —-* *—- —-* *—- —- —- —- —- —- —- —- —- —-* *—- —-* *—- —-* *—- —-* *————————————————————————–*/#include “headers.h”// PURPOSE: To sort the linked-list of nodes pointed to by ‘nodePtr’ using// the merge sort algorithm. Returns the first node of the sorted list.struct Node* mergeSort (struct Node* nodePtr ){ if ( (nodePtr == NULL) || (nodePtr->nextPtr_ == NULL) ) { return(nodePtr); } struct Node* run; struct Node* run2; struct Node* lastPtr = NULL; for ( run = run2 = nodePtr; (run2 != NULL) && (run2->nextPtr_ != NULL); lastPtr = run, run = run->nextPtr_, run2 = run2->nextPtr_->nextPtr_ ); lastPtr->nextPtr_ = NULL; run2 = mergeSort(run); run = mergeSort(nodePtr); nodePtr = NULL; lastPtr = NULL; while ( (run != NULL) && (run2 != NULL) ) { if (run->value_ < run2->value_) { if (nodePtr == NULL) { nodePtr = lastPtr = run; } else { lastPtr = lastPtr->nextPtr_ = run; } run = run->nextPtr_; } else { if (nodePtr == NULL) { nodePtr = lastPtr = run2; } else { lastPtr = lastPtr->nextPtr_ = run2; } run2 = run2->nextPtr_; } } if (run == NULL) { if (lastPtr == NULL) { nodePtr = run2; } else { lastPtr->nextPtr_ = run2; } } else { if (lastPtr == NULL) { nodePtr = run; } else { lastPtr->nextPtr_ = run; } } return(nodePtr);}struct Node* mergeSortWrapper(struct Node* nodePtr ){ nodePtr = mergeSort(nodePtr); print(nodePtr); return(nodePtr);}

Expert Answer


Answer to Additional Files For Another Question: https://www.chegg.com/homework-help/questions-and-answers/trying-figure-needs-hea…

OR