-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.c
86 lines (77 loc) · 1.32 KB
/
Node.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Tyler Monaghan
Node.c
This program creates nodes for a linked list
*/
#include"Node.h"
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/** Creates node with default values next = NULL and data = 0 */
struct Node_t* makeNode1(struct Node_t* it)
{
it->next = NULL;
it->data = 0;
return it;
}
/* Creates node with specified data value */
struct Node_t* makeNode2(struct Node_t* it, int data)
{
it->next = NULL;
it->data = data;
return it;
}
/** Creates node with specified data value and pointer to next */
struct Node_t* makeNode4(struct Node_t* it, int data, struct Node_t* next)
{
it->next = next;
it->data = data;
return it;
}
/** Frees a node */
struct Node_t* freeNode(struct Node_t* it)
{
if (it != NULL)
{
free(it);
it = NULL;
}
return NULL;
}
/** Setter for data */
int setData(struct Node_t* it, int data)
{
it->data = data;
return data;
}
/* Setter for next */
struct Node_t* setNext(struct Node_t* it, struct Node_t* next)
{
if (it == NULL)
{
it = next;
}
else
{
it->next = next;
}
return next;
}
/** Getter for data */
int getData(struct Node_t* it)
{
if (it == NULL)
{
return 0;
}
return it->data;
}
/** Getter for next */
struct Node_t* getNext(struct Node_t* it)
{
if (it == NULL)
{
return NULL;
}
return it->next;
}