-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.h
More file actions
66 lines (48 loc) · 1.77 KB
/
linkedlist.h
File metadata and controls
66 lines (48 loc) · 1.77 KB
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
/* linked-list learning exercise. Define data type in linkedlistdata.h */
#ifndef LINKEDLIST_H__
#define LINKEDLIST_H__
#include "linkedlistdata.h"
typedef struct node_ {
stackdata val;
struct node_* next;
} node, * node_ptr;
/* returns new head
this one is like adding to a stack
head will thus change so return new head */
node_ptr push_front(node_ptr head, node_ptr to_add);
/* this is like adding to a queue */
node_ptr push_back(node_ptr head, node_ptr to_add);
/* We add node by num in ascending order */
void add_sorted_node(node_ptr head, node_ptr to_add);
/* find by value */
node_ptr find_by_value(node_ptr head, stackdata value);
/* return length of ll */
size_t length(node_ptr head);
/* create a linked list node */
node_ptr make_node(stackdata value);
/* free all nodes */
void free_list(node_ptr head);
//return new head
node_ptr delete_node(node_ptr head, node_ptr to_delete);
/* return last node in ll */
node_ptr get_last_node(node_ptr head);
/* print ll */
void printlist(node_ptr head);
/* is sorted by value */
int is_sorted(node_ptr head);
/* reverse nodes in list - iterative method */
node_ptr reverse_nodes(node_ptr head);
/* print from end back */
void reverse_print(node_ptr p);
/* recursive reversal of ll nodes */
node_ptr reverse_r(node_ptr pivot, node_ptr backward);
/* ascending - swaps nodes */
node_ptr selection_sort(node_ptr head);
/* insert n after j - return new ll */
node_ptr insert(node_ptr head, int n, int j);
/* functions below are learning exercises rather than useful linked list functions */
/* convert n to binary number and store in new ll, least significant bit at head */
node_ptr insert_binary(int n);
/* convert binary from insert_binary function back to decimal */
unsigned binary2decimal(node_ptr head);
#endif /* LINKEDLIST_H__ */