singly_linked_list.c - SYSC 2006 Lab 8 A module that implements a singly-linked list of integers#include#include#include#include <assert.h> assert

singly_linked_list.c - SYSC 2006 Lab 8 A module that...

This preview shows page 1 - 2 out of 5 pages.

/* SYSC 2006 Lab 8 A module that implements a singly-linked list of integers. */ #include <assert.h> // assert #include <stdlib.h> // malloc, free #include <stdbool.h> #include <stdio.h> // printf #include "singly_linked_list.h" /************************************************************* * Functions presented in lectures. *************************************************************/ /* Return a pointer to a new intnode_t (a node in a singly-linked list). Parameter value: the integer to be stored in the node. Parameter next: a pointer to the node that the new node should point to. This pointer should be NULL if the new node is the last node in the linked list. Terminate (via assert) if memory for the node cannot be allocated. */ intnode_t *intnode_construct(int value, intnode_t *next) { intnode_t *p = malloc(sizeof(intnode_t)); assert (p != NULL); p->value = value; p->next = next; return p; } /* Parameter head points to the first node in a linked list, or is NULL if the linked list is empty. Insert a node containing the specified integer value at the front of the linked list, and return a pointer to the first node in the modified list. */ intnode_t *push(intnode_t *head, int value) { return intnode_construct(value, head); } /* Parameter head points to the first node in the list.
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture