5 link_t
* list_new(int value
) {
7 link_new
= malloc(sizeof(link_t
));
8 link_new
->value
= value
;
13 link_t
* list_append(link_t
* head
, int value
) {
16 return head
= list_new(value
);
18 link_t
* head_first
= head
;
19 while (head
->next
!= NULL
) {
22 head
->next
= list_new(value
);
27 link_t
* list_prepend(link_t
* head
, int value
) {
28 link_t
* first_link
= list_new(value
);
30 first_link
->next
= head
;
34 link_t
* list_insert(link_t
* head
, unsigned index
, int value
) {
37 return list_prepend(head
, value
);
38 } else if (index
== list_count(head
)) {
39 return list_append(head
, value
);
41 link_t
* link_insrt
= list_new(value
);
42 link_t
* head_first
= head
;
43 link_t
* head_next
= NULL
;
44 for (unsigned i
= 0; i
< index
-1; i
++) {
47 head_next
= head
->next
;
48 head
->next
= link_insrt
;
50 head
->next
= head_next
;
55 link_t
* list_delete(link_t
* head
, unsigned index
) {
56 link_t
* head_prev
= NULL
;
57 link_t
* head_next
= NULL
;
60 head_next
= head
->next
;
65 link_t
* head_first
= head
;
66 for (unsigned i
= 0; i
< index
-1; i
++) {
71 head_next
= head
->next
;
74 head
->next
= head_next
;
79 unsigned list_count(link_t
* head
) {
82 while (head
!= NULL
) {
89 void list_set(link_t
* head
, unsigned index
, int value
) {
92 while (head
!= NULL
&& count
< index
) {
96 if (head
!= NULL
) { head
->value
= value
; }
99 int list_get(link_t
* head
, unsigned index
) {
102 while (head
!= NULL
&& count
< index
) {
113 void list_clear(link_t
* link
) {
114 link_t
* next_link
= NULL
;
116 while (link
!= NULL
) {
117 next_link
= link
->next
;