diff --git a/assignment9.txt b/assignment9.txt new file mode 100644 index 0000000..73c1e76 --- /dev/null +++ b/assignment9.txt @@ -0,0 +1,9 @@ +Drew French + +1) malloc() takes size_t & number of bytes of space and allocates that amount of bytes; you then need to fill the space. Calloc takes size_t, number of bytes per element, and number of elements and allocates [bytes per element] for each element. This space is filled by these elements. + +2) Maybe iterate through it to fill it with integers and multiply the number of integers by 4 to get the amount of bytes? + +3) Heap resets only when the computer is restarted; stack resets when the program ends. + +4) If it's NULL, there is no space. \ No newline at end of file diff --git a/linkedlist.c b/linkedlist.c new file mode 100644 index 0000000..2688af3 --- /dev/null +++ b/linkedlist.c @@ -0,0 +1,64 @@ +/* Drew French */ + +/* Does stuff with + * linked lists. + */ + +/* Did not finish; trying + * to figure out why what + * there is so far is + * getting errors. + */ + +#include +#include + +typedef struct node +{ + int n; + struct node *next; +} nodeType; + +void printList(nodeType *head) +{ + nodeType *current = head; + while(current != NULL) + { + printf("%d\n", current->n) + current = current->next; + } +} + +void clear(nodeType *head) +{ + nodeType *current = head; + while(current != NULL) + { + free(*current); + } +} + +int main() +{ + nodeType *head = NULL; + + head = malloc(sizeof(nodeType)); + head->n = 3; + head->next = malloc(sizeof(nodeType)); + head->next->n = 1; + head->next->next = malloc(sizeof(nodeType)); + head->next->next->n = 4; + head->next->next->next = malloc(sizeof(nodeType)); + head->next->next->next->n = 1; + head->next->next->next->next = malloc(sizeof(nodeType)); + head->next->next->next->next->n = 5; + head->next->next->next->next->next = malloc(sizeof(nodeType)); + head->next->next->next->next->next->n = 9; + head->next->next->next->next->next->next = NULL; + + printList(*head); + + clear(*head); + + return 0; +} \ No newline at end of file