Concept explainers
Explanation of Solution
Perform Next-fit search instead of First-fit search:
In the “Section 9.9.12 (mm.c)”, remove the lines that starts from “/* $begin mmfirstfit */” and ends with “return NULL; /* No fit */”.
Add the following highlighted code to the “Section 9.9.12 (mm.c)”. The modified “mm.c” file is as follows:
/* Global variables */
static char *heap_listp = 0; /* Pointer to first block */
// Rover for Next fit
static char *rover;
/* Function prototypes for internal helper routines */
static void *extend_heap(size_t words);
heap_listp += (2 * WSIZE);
/* $end mminit */
// Assign heap_listp to rover
rover = heap_listp;
/* $begin mminit */
/* Extend the empty heap with a free block of CHUNKSIZE bytes */
bp = PREV_BLKP(bp);
}
/* $end mmfree */
// If condition to check the rover is not representing the free block
if ((rover > (char *)bp) && (rover < NEXT_BLKP(bp)))
// Assign bp to rover
rover = bp;
/* $begin mmfree */
return bp;
}
{
/* Next fit search instead of first fit search*/
// Assign rover to the character pointer oldrover
char *oldrover = rover;
/* Finding next fit using for loop */
// For loop to search from rover to the end of the list
for (; GET_SIZE(HDRP(rover)) > 0; rover = NEXT_BLKP(rover))
// If condition to check allocation and size of rover
if (!GET_ALLOC(HDRP(rover)) && (asize <= GET_SIZE(HDRP(rover))))
// Return rover
return rover;
// For loop to search from start of list to old rover
for (rover = heap_listp; rover < oldrover; rover = NEXT_BLKP(rover))
// If condition to check allocation and size of rover
if (!GET_ALLOC(HDRP(rover)) && (asize <= GET_SIZE(HDRP(rover))))
// Return rover
return rover;
// Otherwise return null
return NULL;
}
/* $end mmfirstfit */
Filename: main.c
// Include libraries
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
// Include required header files
#include "csapp...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- Write a class that when given the MDG and the number of iterations it applies the Munch clustering algorithm and return the clustering arrangement as output. This class will contain the components from the previous questions. Appendix A contains the pseudocode of the Munch clustering algorithm using the Random Mutation Hill Climbing algorithm. However, any single population heuristic search algorithm can be used.arrow_forwardWrite a function, to be included in an unsorted linked list class, called replace_item, that will receive two parameters, one called olditem, the other called newitem. The function will replace all occurrences of olditem with newitem ( if olditem exists !! ) and it will return the number of replacements done.arrow_forwardYou are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this homework. The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then print all the current keys to command line in one…arrow_forward
- Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function. I have 5 tabs: I have tried every solution I can think of with no luck. These are the guides: arrayListType.h arrayListTypeImp.cpp: main.cpp unorderedArraryListType.h unorderedArrayListTypeImp.cpp I am needing these in order to pass the assignment in Cengage Mindtap, please help with codes for each one if possible.arrow_forwardCOMPLETE THIS CODE and make sure it passes all the test cases.// EXERCISE 4.1 MYLIST ITERATIVE CATENATE MUTATE /** * Catenate two MyLists, listA and listB. Mutate listA. * @param listA is a MyList object. * @param listB is a MyList object. * @return a list consisting of the elements of listA followed by the * elements of listB. */public static MyList iterCatMutList(MyList listA, MyList listB) { }arrow_forwardNeed help making a java file that combines both linearSearch and binarySearch •Both search methods must use the Comparable<T> interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code. //code from textbook //linearSearch public static <T> boolean linearSearch(T[] data, int min, int max, T target) { int index = min; boolean found = false; while (!found && index <= max) { found = data [index].equals(target); index++; } return found; } //binarySearch public static <T extends Comparable<T>> boolean binarySearch(T[] data, int min, int max, T target) { boolean found = false; int midpoint = (min + max)/2; if (data[midpoint].compareTo(target)==0)…arrow_forward
- B) By using classes, write the appropriate program that implements creation of the head pointer of a linked list and then add first node to the list and make it pointing to null.arrow_forwardQ1. Given the following set: pets = {"cat", "dog", "horse"}, replace the word "dog" with "cow". You cannot assume that you know the index of "dog" - you must find it using code.arrow_forwardThis in c++.arrow_forward
- TaskDeclare and implement 5 classes: FloatArray, SortedArray,FrontArray, PositiveArray & NegativeArray.1- The FloatArray class stores a dynamic array of floats and itssize. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the end of the array.- Overloading for the insertion operator << to write the array to afile (ofstream)- Overloading for the extraction operator >> to read the arrayelements from the file (ifstream) and add them to the array.- A destructor to deallocate the array2- The SortedArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the right place in the arraysuch that the array remains sorted with every add. Don’t add tothe array then sort but rather add in the right place.3- The FrontArray inherits from FloatArray. It has:- A parameterized constructor that takes the array size.- An add method that adds a float at the front of…arrow_forwardProblem 3: In classroom, we implemented MyStack by including an ArrayList as private data field of the class (using composition). In this problem, we will use another way to implement the stack class. Define a new MyStack class that extends ArrayList. Draw the UML diagram for the classes and then implement MyStack. Write a test program that prompts the user to enter five strings and displays them in reverse order. (1) Your UML diagram: (3)arrow_forwardThis one in c++.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education