Monash University > CSSE > CSE1303 > Part A > Lectures > Lecture A07 notes
/* 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