This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist.h
84 lines (69 loc) · 1.75 KB
/
linkedlist.h
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
#ifndef LINKEKLIST_H
#define LINKEKLIST_H
#define CELL_DEFAULT_VALUE 0
/**
* Prototype for node_t structure
*/
struct node_t;
/**
* Representation of individual memory cells
*/
struct node_t {
struct node_t *next;
struct node_t *prev;
int value;
};
/**
* Creates the first node
* @return First node for use in set
*/
struct node_t* create_first_node();
/**
* Creates a new node, given the left
* and the right nodes (they can be NULL
* if not avaliable) and the cell value
*/
struct node_t* create_new_node(struct node_t* left, struct node_t* right, int value);
/**
* Change the current node to the left node
* (it's created if it not exists)
*/
void move_left(struct node_t** cur);
/**
* Change the current node to the right node
* (it's created if it not exists)
*/
void move_right(struct node_t** cur);
/**
* Subtract the value for a given cell by one
*/
void decrement_value(struct node_t* node);
/**
* Add the value for a given cell by one
*/
void increment_value(struct node_t* node);
/**
* Change a value for a given cell
*/
void change_value(struct node_t* node, int value);
/**
* Gets the value for a given existing cell
*/
int get_value(struct node_t* cur);
/**
* Return the value of the left cell without change the actual one
* @return value to the left cell
*/
int peek_left_value(struct node_t* node);
/**
* Return the value of the right cell without change the actual one
* @return value to the right cell
*/
int peek_right_value(struct node_t* node);
/**
* Destroy the node set by giving any node of it
* The method follow the left and right nodes,
* ensuring all set gets deleted
*/
int destroy_all_nodes(struct node_t* any_node);
#endif