Monash University > CSSE > CSE1303 > Part A > Lectures > Lecture A07 notes

CSE1303 Computer Science
Semester 3 (summer), 2003
Part A
Lecture A07 notes: Nodes

In this lecture

Reading: Reviewing Lists Nodes

Code for this lecture

/* node.h */
#ifndef NODEH
#define NODEH

struct NodeRec
{
 float              value;
 struct NodeRec*    nextPtr;
};

typedef struct NodeRec Node;

Node* makeNode(float item);

#endif

/* node.c */
#include <stdio.h>
#include <stdlib.h>
#include "node.h"


/* Make a new node which contains item. */
Node* makeNode(float item)
{
  Node* newNodePtr = (Node*)malloc(sizeof(Node));

  if (newNodePtr == NULL)
  {
     fprintf(stderr, "Out of memory");
     exit(1);
  }
  else
  {
     /* initialising the node's contents */
     newNodePtr->value = item;
     newNodePtr->nextPtr = NULL;
  }
  return newNodePtr;
}

[ Top | Home ]
Last Updated: Tuesday 02 December 2003 22:29:28