1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h>
#include <stdlib.h>
struct Node { // SINGLY LINKED LIST
int value;
struct Node* prev;
struct Node* next;
}; // require ≥20 bytes
int main(int argc, char *argv[]) {
// empty list
struct Node* head = NULL; // always set head to either NULL or malloc(…)
struct Node* tail = NULL;
head = malloc(sizeof(*head)); // allocated ≥20 bytes [OOP]
tail = head;
head -> value = 2;
head -> prev = NULL;
// WE ARE HERE as of 11:07 AM
head -> next = malloc( sizeof(*(head -> next)) );
head -> next -> value = 4;
head -> next -> prev = head;
head -> next -> next = NULL;
tail = head -> next;
// FILL IN TO HERE
free(head -> next);
free(head);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2016 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.