Lecture 12 Linked List Code
ll.h
#ifndef LL_H
#define LL_H
typedef struct Node {
int value;
struct Node* next;
} Node;
Node* make_node(int value, Node* next);
#endif
ll.c
#include <stdlib.h>
#include <stdio.h>
#include "ll.h"
Node* make_node(int value, Node* next) {
Node* node = (Node*)malloc(sizeof(Node));
node->value = value;
node->next = next;
return node;
}
main.c
#include <stdlib.h>
#include <stdio.h>
#include "ll.h"
int main() {
Node* n1 = make_node(4, NULL);
Node* n2 = make_node(7, n1);
Node* n3 = make_node(3, n2);
printf(
"%d%d%d\n",
n3->value,
n3->next->value,
n3->next->next->value);
free(n3);
free(n2);
free(n1);
}
Makefile
CC = gcc
CFLAGS = -g -Wall -std=c11
try_lists: main.o ll.o
$(CC) $(CFLAGS) -o try_lists main.o ll.o
main.o: main.c ll.h
$(CC) $(CFLAGS) -c main.c
ll.o: ll.c ll.h
$(CC) $(CFLAGS) -c ll.c