Here is the code we wrote today:
#include <stdio.h>
#include <stdlib.h>
struct listNode {
int value;
struct listNode* next;
};
typedef struct listNode node;
node* addFront(node* list, int val) {
node* newNode = (node*) malloc(sizeof(node));
//(*newNode).value = val;
newNode -> value = val;
newNode -> next = list;
return newNode;
}
//curr -> next -> value
//(*((*curr).next)).value
void printList(node* curr) {
while(curr != NULL) {
printf("%d ", curr -> value);
curr = curr -> next;
}
printf("\n");
}
int main() {
node* list = NULL;
list = addFront(list, 214);
list = addFront(list, 142);
list = addFront(list, 141);
printList(list);
}