Question: MUST be written in C Language and using the compiler gcc NEED HELP WITH hw11 ALREADY DID hw10 **This is the homework assignment** On this
MUST be written in C Language and using the compiler gcc NEED HELP WITH hw11 ALREADY DID hw10 **This is the homework assignment** On this day in 1184 BC The Greeks entered Troy using the Trojan Horse. Which has nothing to do with computer science. For this assignment you will divide up HW-10 and develop a Makefile to practice using the compiler and linker with libraries. All files will be strictly C code - no C++! Part 1 (10 points): ------------------ Seperate HW-10 into the following 4 files: 1) One file will contain all of the code/functions that build the doubly-linked linked list. Call it hw11-yourname-A.c This file will also require a header file. Call it hw11-yourname-A.h 2) One file will contain all of the code/functions that build the garbage linked list. Call it hw11-yourname-B.c This file will also require a header file. Call it hw11-yourname-B.h 3) One file will contain all of the code/functions that display the linked lists. Call it hw11-yourname-C.c This file will also require a header file. Call it hw11-yourname-C.h 4) One file will contain all of the code/functions that free the linked lists. Call it hw11-yourname-D.c This file will also require a header file. Call it hw11-yourname-D.h Write a Makefile that compiles and links the above in 2 (two) steps. You MUST call this Makefile "Makefile1". Part 2 (5 points): ------------------ Write a Makefile that creates a STATIC library/archive (hw11-lib-yourname.a) out of the associated *.c files (1, 2, 3, & 4) and that compiles and links hw11-yourname-main.c with your static library. You MUST call this Makefile "Makefile2". Part 3 (5 points): ------------------ Write a Makefile that creates SHARED a library (hw11-lib-yourname.so) out of the associated c files (1, 2, 3, & 4) and that compiles and links hw11-yourname-main.c with your shared library. You MUST call this Makefile "Makefile3". Part 4 (20 points): ------------------- Modify hw11-yourname-main.c to use the SHARED library (hw11-lib-yourname.so) dynamically (using dlopen). Call this MAIN program hw11-yourname-4.c Write a Makefile that compiles and links hw11-yourname-4.c with your dynamic shared library. You MUST call this Makefile "Makefile4". Note that all of the functionallity must exist in this program as it did in hw10 to earn full credit.
**This is the homework assignment**
**This was homework 10 to be used for homework 11**
On this day in 1933 Prohibition ended in the United States. Sounds like a reason to celebrate by learning how to take out the garbage. The assignment is to modify hw8 such that link removal is managed by your own garbage collection system. Part 1: ------- You MUST modify your hw8 such that the code for displaying the list contents is now contained in two functions called: DISPLAY_INORDER(xxxx) DISPLAY_POSTORDER(xxxx) Where xxxx will be whatever parameters need to be passed. You MUST also have a routine that deletes (frees) the nodes of the link list. This routine will get called at the end of the program. The function will be called: FREE_INORDER(xxxx) Part 2: ------- You must now randomly determine a number of nodes to delete and randomly determine what specific nodes to delete. You might want to use something like: number2Delete = rand() % number2Add + 3; for (i = 0; i < number2Delete; i++) { // Pick a random node (payload) to delete. link2Delete = (rand() % number2Add); Part 3: ------- For each node selected for removal, you must not yet actually delete it from memory. Rather you will adjust your link list to skip over it and use a second linked list (our trash list) to record the node slated for deletion. You must also account for the case where an already deleted node gets selected for removal again. Finally, note that "link2Delete" refers to the payload section. So, you will have to search the linked list to find the node to delete. Part 4: ------- Once you have processed/recorded all of the nodes slated for removal, you MUST display the contents of your trash list via a function called: DISPLAY_TRASH(xxxx) You must then you MUST free up the trash list and display the remaining contents of the original list via calls to DISPLAY_INORDER(xxxx) DISPLAY_POSTORDER(xxxx) Finally, you must call the FREE_INORDER(xxxx) function. **this was homework 10 to be used for homework 11**
***hw10 file **
#include
#include
#include
#include
struct node
{
int data;
struct node *next;
struct node *prev;
}
*trashHead, *trashTail, *trashCurrent;
void DisplayInorder (struct node *head1); // declaring function
void DisplayPostorder (struct node *tail1); // declaring function
void DisplayTrash (struct node *trashHead1); // declaring function
void FreeInorder (struct node *head2); // declaring function
void FreeTrash (struct node *trashHead2); // declaring function
int AddToTrash (struct node *toTrash, int trashSize1); // declaring function
int main( int argc, char *argv[] )
{
// Implement and check command line arguments
if( argc == 2 )
printf("Command line argument:\t%s ", argv[1]);
else if( argc > 2 )
{
printf("Too many arguments supplied. ");
return 1;
}
else
{
printf("One argument expected. ");
return 2;
}
// Declare thes structure and the variable and the pointers
int i, counter, removal, trashSize = 0;
counter = atoi(argv[1]);
struct node *current, *temp, *head, *tail;
// setting the pointer to null
head = NULL;
// inserts the numbers needed with the data given
for(i=0; i < counter; i++)
{
printf("Input data:\t%d ", i);
if (head == NULL)
{
if ((temp = (struct node *)malloc(sizeof(struct node))) != NULL)
{
// again seeting the pointers
temp->data = i;
temp->next = NULL;
temp->prev = NULL;
current = temp;
head = temp;
}
else
{
printf("Memory allocation failed");
return 1;
}
}
else
{
if ((temp = (struct node *)malloc(sizeof(struct node))) != NULL)
{
temp->data = i;
current->next = temp;
temp->prev = current;
current = temp;
}
else
{
printf("Memory allocation failed");
return 1;
}
}
}
// Set the tail pointer
tail = current;
// Print blank line make it look pretty
printf(" ");
// Print the list forwards
DisplayInorder(head);
// Print blank line make it look pretty
printf(" ");
// Print the list backwards
DisplayPostorder(tail);
// the random function to randomly select how many numbers it should remove and put it in the trash can
removal = rand() % counter + 3;
for (i = 0; i < removal; i++)
{
// use of the random function again to find out what number in particular is going to delete
removal = (rand() % counter);
//printf("%d ", removal);
// this will go through the list and determine which one is the one getting deleted.
current = head;
while (current)
{
if (current->data == removal)
{
if (current->prev == NULL)
{
// Set the next node in the linked list to head
current->next->prev = NULL;
head = current->next;
//adding it to the trash list just from the head anf pushing it in
trashSize = AddToTrash(current, trashSize);
printf("I just changed the head");
break;
}
else
{
// Change prev and next pointers to exclude this node
if (current->next != NULL)
{
current->next->prev = current->prev;
current->prev->next = current->next;
}
// Drop the pointers to the current node, as it is at the tail of the linked list
else // (current->next == NULL)
{
current->prev->next = NULL;
}
//Do something to put the node current into the Trash linked list
printf("I just sent %d to trash. ", removal);
trashSize = AddToTrash(current, trashSize);
break;
}
}
else if (current->next != NULL)
current = current->next;
else
{
//printf("Something went wrong or selected two numbers);
break;
}
}
}
// Display the trash linked list
DisplayTrash(trashHead);
// Print blank line
printf(" ");
// Print the list forwards
DisplayInorder(head);
// Print blank line
printf(" ");
// Print the list backwards
DisplayPostorder(tail);
// Free the array(s)
FreeInorder(head);
return 0;
}
void DisplayInorder (struct node *head1)
{
// Print the list forwards
while (head1)
{
// Print out data, tab delimited
printf("Left to right output:\t%d ", head1->data);
head1 = head1->next;
}
}
void DisplayPostorder (struct node *tail1)
{
while (tail1)
{
// Print out data, tab delimited
printf("Right to left output:\t%d ", tail1->data);
tail1 = tail1->prev;
}
}
int AddToTrash (struct node *toTrash, int trashSize1)
{
if (trashSize1 == 0)
{
trashHead = toTrash;
trashCurrent = toTrash;
trashTail = toTrash;
toTrash->prev = NULL;
toTrash->next = NULL;
trashSize1++;
}
else
{
toTrash->next = NULL;
trashCurrent->next = toTrash;
toTrash->prev = trashCurrent;
trashCurrent = trashCurrent->next;
trashTail = trashCurrent;
trashSize1++;
}
return trashSize1;
}
void DisplayTrash (struct node *trashHead1)
{
// Print the trash list forwards
while (trashHead1)
{
// Print out data, tab delimited
printf("Trash output:\t%d ", trashHead1->data);
if (!trashHead1->next)
{
free(trashHead1);
break;
}
trashHead1 = trashHead1->next;
free(trashHead1->prev);
}
}
void FreeTrash (struct node *trashHead2)
{
while (trashHead2)
{
if (!trashHead2->next)
{
free(trashHead2);
break;
}
trashHead2 = trashHead2->next;
free(trashHead2->prev);
}
}
void FreeInorder (struct node *head2)
{
while (head2)
{
if (!head2->next)
{
free(head2);
break;
}
head2 = head2->next;
free(head2->prev);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
