9ebb34817e5982fa3b3131e388d01b320f6a3a70
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
;
58 link_t
* head_ret
= NULL
;
62 } else if (index
== 0) {
63 head_next
= head
->next
;
68 link_t
* head_first
= head
;
69 for (unsigned i
= 0; i
< index
-1; i
++) {
74 head_next
= head
->next
;
77 head
->next
= head_next
;
78 head_ret
= head_first
;
80 if (head_ret
!= NULL
) {
87 unsigned list_count(link_t
* head
) {
90 while (head
!= NULL
) {
97 void list_set(link_t
* head
, unsigned index
, int value
) {
100 while (head
!= NULL
&& count
< index
) {
104 if (head
!= NULL
) { head
->value
= value
; }
107 int list_get(link_t
* head
, unsigned index
) {
110 while (head
!= NULL
&& count
< index
) {
121 void list_clear(link_t
* head
) {
122 link_t
* next_link
= NULL
;
124 while (head
!= NULL
) {
125 next_link
= head
->next
;